diff --git a/erlang/src/step2_eval.erl b/erlang/src/step2_eval.erl index a90a2234..149f1d48 100644 --- a/erlang/src/step2_eval.erl +++ b/erlang/src/step2_eval.erl @@ -43,6 +43,8 @@ read(String) -> {error, Reason} -> io:format("error: ~s~n", [Reason]), nil end. +eval({list, [], _Meta}=AST, _Env) -> + AST; eval({list, List, Meta}, Env) -> case eval_ast({list, List, Meta}, Env) of {list, [F|Args], _M} -> erlang:apply(F, [Args]); diff --git a/factor/step2_eval/step2_eval.factor b/factor/step2_eval/step2_eval.factor index ca11c1a7..aa1c06ea 100755 --- a/factor/step2_eval/step2_eval.factor +++ b/factor/step2_eval/step2_eval.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2015 Jordan Lewis. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors arrays assocs combinators continuations fry io -kernel math lib.printer lib.reader lib.types quotations readline -sequences ; +USING: accessors arrays assocs combinators combinators.short-circuit +continuations fry io kernel math lib.printer lib.reader lib.types +quotations readline sequences ; IN: step2_eval CONSTANT: repl-env H{ @@ -34,7 +34,7 @@ DEFER: EVAL : READ ( str -- maltype ) read-str ; : EVAL ( maltype env -- maltype ) - eval-ast dup array? [ + eval-ast dup { [ array? ] [ empty? not ] } 1&& [ unclip dup quotation? [ "not a fn" throw ] unless with-datastack first diff --git a/rust/src/bin/step2_eval.rs b/rust/src/bin/step2_eval.rs index fcf03836..c807e3d7 100644 --- a/rust/src/bin/step2_eval.rs +++ b/rust/src/bin/step2_eval.rs @@ -54,8 +54,14 @@ fn eval(ast: MalVal, env: &HashMap) -> MalRet { // apply list match *try!(eval_ast(ast, env)) { List(ref args,_) => { - let ref f = args.clone()[0]; - f.apply(args[1..].to_vec()) + match args.len() { + 0 => + Ok(list(vec![])), + _ => { + let ref f = args.clone()[0]; + f.apply(args[1..].to_vec()) + } + } }, _ => return err_str("Expected list"), }