mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-19 01:18:40 +03:00
eval: make list and array commands
This commit is contained in:
parent
d8545a57be
commit
37143d067f
@ -370,6 +370,25 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#array">
|
||||
<h3 id="array">
|
||||
array
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
command
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#array?">
|
||||
<h3 id="array?">
|
||||
@ -1244,6 +1263,25 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#list">
|
||||
<h3 id="list">
|
||||
list
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
command
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#list?">
|
||||
<h3 id="list?">
|
||||
|
@ -618,6 +618,63 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#stderr">
|
||||
<h3 id="stderr">
|
||||
stderr
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(Ptr FILE)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#stdin">
|
||||
<h3 id="stdin">
|
||||
stdin
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(Ptr FILE)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#stdout">
|
||||
<h3 id="stdout">
|
||||
stdout
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(Ptr FILE)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#unlink">
|
||||
<h3 id="unlink">
|
||||
|
@ -140,6 +140,25 @@
|
||||
</h1>
|
||||
<div class="module-description">
|
||||
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#abort">
|
||||
<h3 id="abort">
|
||||
abort
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#exit">
|
||||
|
@ -529,6 +529,12 @@ commandIsSymbol [x] =
|
||||
XObj (Sym _ _) _ _ -> return (Right trueXObj)
|
||||
_ -> return (Right falseXObj)
|
||||
|
||||
commandArray :: CommandCallback
|
||||
commandArray args = return $ Right (XObj (Arr args) (Just dummyInfo) Nothing)
|
||||
|
||||
commandList :: CommandCallback
|
||||
commandList args = return $ Right (XObj (Lst args) (Just dummyInfo) Nothing)
|
||||
|
||||
commandLength :: CommandCallback
|
||||
commandLength [x] =
|
||||
case x of
|
||||
|
10
src/Eval.hs
10
src/Eval.hs
@ -104,16 +104,6 @@ eval env xobj =
|
||||
[] -> return (makeEvalError ctx Nothing "No forms in 'do' statement." (info xobj))
|
||||
_ -> return (Right (last ok))
|
||||
|
||||
XObj (Sym (SymPath [] "list") _) _ _ : rest ->
|
||||
do evaledList <- fmap sequence (mapM (eval env) rest)
|
||||
return $ do okList <- evaledList
|
||||
Right (XObj (Lst okList) i t)
|
||||
|
||||
XObj (Sym (SymPath [] "array") _) _ _ : rest ->
|
||||
do evaledArray <- fmap sequence (mapM (eval env) rest)
|
||||
return $ do okEvaledArray <- evaledArray
|
||||
Right (XObj (Arr okEvaledArray) i t)
|
||||
|
||||
-- 'and' and 'or' are defined here because they are expected to short circuit
|
||||
[XObj (Sym (SymPath ["Dynamic"] "and") _) _ _, a, b] ->
|
||||
do evaledA <- eval env a
|
||||
|
@ -215,6 +215,8 @@ dynamicModule = Env { envBindings = bindings
|
||||
, addCommand "cons" 2 commandCons
|
||||
, addCommand "cons-last" 2 commandConsLast
|
||||
, addCommand "append" 2 commandAppend
|
||||
, addCommandConfigurable "array" Nothing commandArray
|
||||
, addCommandConfigurable "list" Nothing commandList
|
||||
, addCommand "macro-error" 1 commandMacroError
|
||||
, addCommand "macro-log" 1 commandMacroLog
|
||||
, addCommandConfigurable "str" Nothing commandStr
|
||||
|
Loading…
Reference in New Issue
Block a user