mirror of
https://github.com/carp-lang/Carp.git
synced 2024-10-12 04:58:18 +03:00
Merge branch 'master' of github.com:carp-lang/Carp
This commit is contained in:
commit
0fae38847e
1
.gitignore
vendored
1
.gitignore
vendored
@ -11,3 +11,4 @@
|
||||
/out/main.c
|
||||
/.DS_Store
|
||||
/Carp.prof
|
||||
dist/
|
||||
|
@ -53,6 +53,7 @@ executable carp
|
||||
build-depends: base
|
||||
, CarpHask
|
||||
, containers
|
||||
, haskeline
|
||||
, process
|
||||
default-language: Haskell2010
|
||||
|
||||
|
@ -70,6 +70,7 @@ To build this example, save it to a file called 'example.carp' and load it with
|
||||
* Reini Urban
|
||||
* Anes Lihovac
|
||||
* Jonas Granquist
|
||||
* Veit Heller
|
||||
|
||||
|
||||
## License
|
||||
|
25
app/Main.hs
25
app/Main.hs
@ -1,8 +1,10 @@
|
||||
module Main where
|
||||
|
||||
import Control.Monad
|
||||
import Control.Monad.IO.Class
|
||||
import System.Console.Haskeline (getInputLine, InputT, runInputT, defaultSettings)
|
||||
import qualified System.Environment as SystemEnvironment
|
||||
import System.IO (hFlush, stdout)
|
||||
import System.IO (stdout)
|
||||
import System.Info (os)
|
||||
import qualified Data.Map as Map
|
||||
import ColorText
|
||||
@ -25,16 +27,19 @@ defaultProject = Project { projectTitle = "Untitled"
|
||||
, projectPrompt = if os == "darwin" then "鲮 " else "> "
|
||||
}
|
||||
|
||||
repl :: Context -> String -> IO ()
|
||||
repl :: Context -> String -> InputT IO ()
|
||||
repl context readSoFar =
|
||||
do putStrWithColor Yellow (if null readSoFar then (projectPrompt (contextProj context)) else " ") -- 鲤 / 鲮
|
||||
hFlush stdout
|
||||
input <- fmap (\s -> readSoFar ++ s ++ "\n") getLine
|
||||
case balance input of
|
||||
0 -> do let input' = if input == "\n" then contextLastInput context else input
|
||||
context' <- executeString context input' "REPL"
|
||||
do let prompt = strWithColor Yellow (if null readSoFar then (projectPrompt (contextProj context)) else " ") -- 鲤 / 鲮
|
||||
input <- (getInputLine prompt)
|
||||
case input of
|
||||
Nothing -> return ()
|
||||
Just i -> do
|
||||
let concat = readSoFar ++ i ++ "\n"
|
||||
case balance concat of
|
||||
0 -> do let input' = if concat == "\n" then contextLastInput context else concat
|
||||
context' <- liftIO $ executeString context input' "REPL"
|
||||
repl (context' { contextLastInput = input' }) ""
|
||||
_ -> repl context input
|
||||
_ -> repl context concat
|
||||
|
||||
arrayModule :: Env
|
||||
arrayModule = Env { envBindings = bindings, envParent = Nothing, envModuleName = Just "Array", envUseModules = [], envMode = ExternalEnv }
|
||||
@ -101,5 +106,5 @@ main = do putStrLn "Welcome to Carp 0.2.0"
|
||||
context <- foldM executeCommand (Context startingGlobalEnv (TypeEnv startingTypeEnv) [] projectWithCarpDir "")
|
||||
(map Load (preludeModules (projectCarpDir projectWithCarpDir)))
|
||||
context' <- foldM executeCommand context (map Load args)
|
||||
repl context' ""
|
||||
runInputT defaultSettings (repl context' "")
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
<!-- This presentation is made to be run in the Deckset app. -->
|
||||
|
||||
# Introduction to Carp
|
||||
|
||||
---
|
||||
@ -413,9 +415,9 @@ Will allocate new memory and leave the old data as-is.
|
||||
|
||||
```
|
||||
(let [xs [1 2 3 4 5]]
|
||||
(transform Int.str &xs))
|
||||
(copy-map Int.str &xs))
|
||||
|
||||
transform : (λ [(λ [a] b) (Ref (Array a))] (Array b)) ;; This type might be buggy!!!
|
||||
copy-map : (λ [(λ [a] b) (Ref (Array a))] (Array b)) ;; This type might be buggy!!!
|
||||
```
|
||||
|
||||
---
|
||||
@ -423,10 +425,10 @@ transform : (λ [(λ [a] b) (Ref (Array a))] (Array b)) ;; This type might be bu
|
||||
|
||||
```
|
||||
(let [xs [1 2 3 4 5]]
|
||||
(map square xs))
|
||||
(endo-map square xs))
|
||||
```
|
||||
|
||||
Ownership of 'xs' is passed to the map function, which will mutate the array and return it.
|
||||
Ownership of 'xs' is passed to the 'endo-map' function, which will mutate the array and return it.
|
||||
|
||||
---
|
||||
# Behind the scenes
|
||||
|
@ -32,6 +32,7 @@
|
||||
* Splicing in macros
|
||||
* Pattern matching on arguments in macros?
|
||||
* 'not=' function/macro
|
||||
* Some lists and similar things generated by built in dynamic functions like 'cons' etc don't create proper Info for their XObjs
|
||||
|
||||
## Language Design Considerations
|
||||
* What's the correct type of the variable in a set!-form, i.e. (set! &x value) or (set! x value)
|
||||
@ -51,7 +52,6 @@
|
||||
* Enable printing of typed AST:s at the REPL to help debug unresolved type variables etc.
|
||||
* Proper error handling when defining invalid struct types (right now it crashes)
|
||||
* Stop evalutaion of forms after errors to avoid "Trying to refer to undefined symbol" error
|
||||
* Built in REPL history (without using rlwrap)
|
||||
* Preserve whitespace to allow saving forms back to disk
|
||||
* Refactorings at the REPL. Rename, extract function, add/remove parameter?
|
||||
* Hide instances of templates/generic functions when printing the environment (by default, allow it as a setting)
|
||||
|
Loading…
Reference in New Issue
Block a user