mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
'defined?' and 'defdynamic-once'
This commit is contained in:
parent
c258296623
commit
7c15ec299b
@ -148,8 +148,8 @@
|
||||
(list
|
||||
'let (array variable from)
|
||||
(list
|
||||
'while (list (if (< step (- step step)) '> '<) variable to)
|
||||
(list
|
||||
'while (list (if (< step (- step step)) '> '<) variable to)
|
||||
(list
|
||||
'do
|
||||
(if (= (length body) 0)
|
||||
()
|
||||
@ -366,3 +366,9 @@ The expression must be evaluable at compile time.")
|
||||
(defmacro until [cnd body]
|
||||
(list 'while (list 'not cnd)
|
||||
body))
|
||||
|
||||
(doc defdynamic-once "creates a dynamic variable and sets its value if it's not already defined.")
|
||||
(defmacro defdynamic-once [var expr]
|
||||
(list 'if (list 'defined? var)
|
||||
()
|
||||
(list 'defdynamic var expr)))
|
||||
|
@ -289,6 +289,13 @@ eval env xobj =
|
||||
XObj (Sym (SymPath [] "use") _) _ _ : _ ->
|
||||
return (makeEvalError ctx Nothing ("Invalid args to `use`: " ++ pretty xobj) (info xobj))
|
||||
|
||||
[XObj (Sym (SymPath [] "defined?") _) _ _, xobj@(XObj (Sym path _) _ _)] ->
|
||||
case lookupInEnv path env of
|
||||
Just found -> return (Right trueXObj)
|
||||
Nothing -> return (Right falseXObj)
|
||||
XObj (Sym (SymPath [] "defined?") _) _ _ : _ ->
|
||||
return (makeEvalError ctx Nothing ("Invalid args to `defined?`: " ++ pretty xobj) (info xobj))
|
||||
|
||||
XObj With _ _ : xobj@(XObj (Sym path _) _ _) : forms ->
|
||||
specialCommandWith xobj path forms
|
||||
XObj With _ _ : _ ->
|
||||
|
Loading…
Reference in New Issue
Block a user