From 5e882e73f76aa7b6fa3ca9263bb8308c13258163 Mon Sep 17 00:00:00 2001 From: Bernd Jendrissek Date: Sun, 10 Feb 2008 16:21:36 +0000 Subject: [PATCH] Support variable argument lists. --- lisp/lisp.c | 5 ++++- lisp/test-expected | 5 +++++ lisp/test-input | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lisp/lisp.c b/lisp/lisp.c index 6f0e467..83e17d4 100644 --- a/lisp/lisp.c +++ b/lisp/lisp.c @@ -506,10 +506,13 @@ union value_pointer builtin_eval(struct environment *env, call_env = environment_new(env); for (p = formal_args; - get_pair(p) != get_pair(constant_nil) && get_pair(args) != get_pair(constant_nil); + (pointer_type(p) == 3 && + get_pair(p) != get_pair(constant_nil) && + get_pair(args) != get_pair(constant_nil)); p = lisp_cdr(p), args = lisp_cdr(args)) { binding_new(call_env, get_charseq_chars(lisp_car(p)), lisp_car(args)); } + binding_new(call_env, get_charseq_chars(p), args); for (p = function_body; get_pair(p) != get_pair(constant_nil); p = lisp_cdr(p)) { sexpr = lisp_cons(lisp_car(p), constant_nil); diff --git a/lisp/test-expected b/lisp/test-expected index 061c814..76321d8 100644 --- a/lisp/test-expected +++ b/lisp/test-expected @@ -30,3 +30,8 @@ lambda -> builtin-macro (quote (17 12 14)) -> (17 12 14) (define (foo x) (if (eq? x 5) 1 (+ (foo (+ x 1)) (foo (+ x 1))))) -> () (foo 2) -> 8 +((lambda rest (cdr rest)) 1 2 3 4) -> (2 3 4) +(define (mylist . rest) rest) -> () +(mylist 1 2 3 4) -> (1 2 3 4) +(define (mymap f l) (if (eq? l (quote ())) (quote ()) (cons (f (car l)) (mymap f (cdr l))))) -> () +(mymap (lambda (x) (+ x 1)) (quote (1 2 4 8))) -> (2 3 5 9) diff --git a/lisp/test-input b/lisp/test-input index cfb71b4..a633e49 100644 --- a/lisp/test-input +++ b/lisp/test-input @@ -28,3 +28,6 @@ lambda (cdr (quote (17 . 42))) (quote (17 . (12 14))) (define (foo x) (if (eq? x 5) 1 (+ (foo (+ x 1)) (foo (+ x 1))))) (foo 2) +((lambda rest (cdr rest)) 1 2 3 4) +(define (mylist . rest) rest) (mylist 1 2 3 4) +(define (mymap f l) (if (eq? l (quote ())) (quote ()) (cons (f (car l)) (mymap f (cdr l))))) (mymap (lambda (x) (+ x 1)) (quote (1 2 4 8))) -- 2.11.4.GIT