eval: make list and array commands

This commit is contained in:
hellerve 2019-09-02 17:42:05 +02:00
parent d8545a57be
commit 37143d067f
6 changed files with 122 additions and 10 deletions

View File

@ -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?">

View File

@ -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">

View File

@ -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">

View File

@ -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

View File

@ -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

View File

@ -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