1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-21 02:27:10 +03:00

erlang, factor, rust: fix empty list eval

This should address remaining implementation fixes for #194.
This commit is contained in:
Joel Martin 2016-04-03 23:16:02 +01:00
parent 6ab3aa4f13
commit 3c88e933a2
3 changed files with 14 additions and 6 deletions

View File

@ -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]);

View File

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

View File

@ -54,8 +54,14 @@ fn eval(ast: MalVal, env: &HashMap<String,MalVal>) -> 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"),
}