Skip to content

Commit

Permalink
Merge pull request #85 from skx/84-symbol
Browse files Browse the repository at this point in the history
Add (symbol).
  • Loading branch information
skx authored Nov 12, 2022
2 parents 48d5325 + c654e9d commit 1e8fbf0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,13 @@ func (ev *Eval) eval(exp primitive.Primitive, e *env.Environment, expandMacro bo
}
return ret

// (symbol
case primitive.Symbol("symbol"):
if len(listExp) != 2 {
return primitive.ArityError()
}
return ev.atom(listExp[1].ToString())

// (env
case primitive.Symbol("env"):

Expand Down
5 changes: 5 additions & 0 deletions eval/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ func TestEvaluate(t *testing.T) {
{`(if false "false" "true")`, "true"},
{"(if false false)", "nil"},

// symbol
{`(set! foo (symbol bar)) (symbol? foo)`, `#t`},

// macroexpand - args are not evaluated
{`(defmacro! foo (fn* (x) x)) (macroexpand (foo (+ 1 2)))`, "(+ 1 2)"},
// quote
Expand Down Expand Up @@ -303,6 +306,8 @@ a
{"(< (length (env)) 200)", "#t"},

// errors
{"(symbol)", primitive.ArityError().ToString()},
{"(symbol 1 2)", primitive.ArityError().ToString()},
{"(invalid)", "ERROR{argument 'invalid' not a function}"},
{"(set! 3 4)", "ERROR{tried to set a non-symbol 3}"},
{"(eval 'foo 'bar)", primitive.ArityError().ToString()},
Expand Down

0 comments on commit 1e8fbf0

Please sign in to comment.