fix bug in repeated function calls

This commit is contained in:
Aidan 2020-07-08 21:09:24 -07:00
parent 93cd5c5a48
commit 81d299aa5e
No known key found for this signature in database
GPG key ID: 327711E983899316
3 changed files with 20 additions and 11 deletions

View file

@ -43,17 +43,16 @@ func (in *Token) Eval(funcs FuncTable, vars VarTable, cnvtUndefVars bool) *Token
switch in.Tag {
case BOOL, NUMBER, STRING:
res = in
res = in.Copy()
case SYMBOL:
res = GetVar(in.Value(), vars)
if res == nil {
res = in
res = in.Copy()
if GetFunction(in.Value(), funcs) == nil {
if cnvtUndefVars {
in.Tag = STRING
res = in
res.Tag = STRING
break
}
@ -63,19 +62,17 @@ func (in *Token) Eval(funcs FuncTable, vars VarTable, cnvtUndefVars bool) *Token
return nil
}
}
res.Next = in.Next
case LIST:
inner := in.Expand()
if inner == nil {
res = in
res = in.Copy()
break
}
if inner.Tag != SYMBOL {
in.Direct(inner.Eval(funcs, vars, cnvtUndefVars))
res = in
res = in.Copy()
break
}

View file

@ -48,6 +48,18 @@ func (t *Token) Append(arg *Token) {
}
}
/* Shallow Copy
* in case of a LIST,
* inner will point to the same list.
*/
func (t *Token) Copy() *Token {
return &Token{
Tag: t.Tag,
inner: t.inner,
Next: t.Next,
}
}
/* Print function which is better suited for repl.
* This one prints the SEXPRs as one would write them.
* Does not evaluate tokens.