Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add (symbol). #85

Merged
merged 1 commit into from
Nov 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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