From 99762c07cad1a2ee43255f9a1fce8e6352203f09 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 24 Jul 2016 13:27:05 +0200 Subject: [PATCH] mes.c: fix apply. --- mes.c | 11 ++++++++--- scm.mes | 5 ++--- test.mes | 4 ++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/mes.c b/mes.c index 9af325f6..b4f03b45 100644 --- a/mes.c +++ b/mes.c @@ -261,6 +261,7 @@ scm *caar (scm *x) {return car (car (x));} scm *cadr (scm *x) {return car (cdr (x));} scm *cdar (scm *x) {return cdr (car (x));} scm *cddr (scm *x) {return cdr (cdr (x));} +scm *caaar (scm *x) {return car (car (car (x)));} scm *caadr (scm *x) {return car (car (cdr (x)));} scm *caddr (scm *x) {return car (cdr (cdr (x)));} scm *cdadr (scm *x) {return cdr (car (cdr (x)));} @@ -334,7 +335,11 @@ apply_env (scm *fn, scm *x, scm *a) return apply_env (efn, x, a); } -scm *make_symbol (char const *s); +scm * +apply (scm *f, scm *x) +{ + return apply_env (f, x, &scm_nil); +} scm * eval (scm *e, scm *a) @@ -349,8 +354,8 @@ eval (scm *e, scm *a) scm *y = assq (e, a); if (y == &scm_f) { //return e; - fprintf (stderr, "eval: no such symbol: %s\n", e->name); - assert (!"unknown symbol"); + fprintf (stderr, "eval: unbound variable: %s\n", e->name); + assert (!"unbound variable"); } return cdr (y); } diff --git a/scm.mes b/scm.mes index bca97918..c6b7dda9 100755 --- a/scm.mes +++ b/scm.mes @@ -109,9 +109,6 @@ (if (= 0 n) '() (cons fill (loop (- n 1)))))))) -(define (apply f args) - (eval (cons f args) (current-module))) - (define-macro (defined? x) `(assq ,x (cddr (current-module)))) @@ -121,6 +118,8 @@ ((and (pair? p) (eq? (car p) '*closure*))) (#t #f))) +(define integer? number?) + (define (assq-set! alist key val) (let ((entry (assq key alist))) (cond (entry (set-cdr! entry val) diff --git a/test.mes b/test.mes index 6c24dd61..98a82c99 100644 --- a/test.mes +++ b/test.mes @@ -244,6 +244,10 @@ (let () (define *top-let-a* '*top-let-a*) #f) (pass-if "top let " (seq? (and (defined? '*top-let-a*) *top-let-a*) #f)) +(pass-if "apply identity" (seq? (apply identity '(0)) 0)) +(pass-if "apply identity 2" (sequal? (apply identity '((0 1))) '(0 1))) +(pass-if "apply append" (sequal? (apply append '((1 2) (3 4))) '(1 2 3 4))) + (newline) (display "passed: ") (display (car (result))) (newline) (display "failed: ") (display (cadr (result))) (newline)