mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
eval: add eval primitive
This commit is contained in:
parent
da32c14197
commit
ca5cc8abeb
@ -98,7 +98,7 @@
|
||||
(list 'build)
|
||||
(list 'run)))
|
||||
|
||||
(defmacro eval [form]
|
||||
(defmacro evaluate [form]
|
||||
(eval-internal form))
|
||||
|
||||
(defmacro e [form]
|
||||
@ -119,7 +119,7 @@
|
||||
(defndynamic collect-into [xs f]
|
||||
(list 'quote
|
||||
(collect-into-internal xs (f) f)))
|
||||
)
|
||||
)
|
||||
|
||||
(defndynamic cond-internal [xs]
|
||||
(if (= (length xs) 0)
|
||||
|
@ -839,6 +839,14 @@ primitiveDefdynamic _ _ [notName, body] = do
|
||||
ctx <- get
|
||||
return (evalError ctx ("`defndynamic` expected a name as first argument, but got " ++ pretty notName) (info notName))
|
||||
|
||||
primitiveEval :: Primitive
|
||||
primitiveEval _ env [val] = do
|
||||
-- primitives don’t evaluate their arguments, so this needs to double-evaluate
|
||||
arg <- eval env val
|
||||
case arg of
|
||||
Left err -> return (Left err)
|
||||
Right ok -> eval env ok
|
||||
|
||||
primitives :: Map.Map SymPath Primitive
|
||||
primitives = Map.fromList
|
||||
[ makePrim "quote" 1 "(quote x) ; where x is an actual symbol" (\_ _ [x] -> return (Right x))
|
||||
@ -858,4 +866,5 @@ primitives = Map.fromList
|
||||
, makeVarPrim "register" "(register name <signature> <optional: override>)" primitiveRegister
|
||||
, makeVarPrim "deftype" "(deftype name <members>)" primitiveDeftype
|
||||
, makePrim "use" 1 "(use MyModule)" primitiveUse
|
||||
, makePrim "eval" 1 "(evaluate mycode)" primitiveEval
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user