From f89507414e7f2a8a43bc73b2a8347977e2c998a4 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 9 Jul 2016 22:47:36 +0200 Subject: [PATCH] eval: disarm lambda. --- mes.c | 12 +++++++----- mes.mes | 1 + test.mes | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/mes.c b/mes.c index 13d86f0c..2475f454 100644 --- a/mes.c +++ b/mes.c @@ -329,6 +329,8 @@ eval_ (scm *e, scm *a) #endif // MACROS if (car (e) == &scm_symbol_quote) return cadr (e); + if (car (e) == &scm_lambda) + return e; #if QUASIQUOTE else if (car (e) == &scm_symbol_unquote) return eval (cadr (e), a); @@ -904,7 +906,7 @@ initial_environment () } scm * -define_lambda (scm *x, scm *a) +define_lambda (scm *x) { return cons (caadr (x), cons (&scm_lambda, cons (cdadr (x), cddr (x)))); } @@ -914,7 +916,7 @@ define (scm *x, scm *a) { if (atom_p (cadr (x)) != &scm_f) return cons (cadr (x), eval (caddr (x), a)); - return define_lambda (x, a); + return define_lambda (x); } scm * @@ -923,20 +925,20 @@ define_macro (scm *x, scm *a) #if DEBUG printf ("\nc:define_macro a="); scm *aa =cons (&scm_macro, - cons (define_lambda (x, a), + cons (define_lambda (x), cdr (assoc (&scm_macro, a)))); display (aa); puts (""); #endif return cons (&scm_macro, - cons (define_lambda (x, a), + cons (define_lambda (x), cdr (assoc (&scm_macro, a)))); } scm * loop (scm *r, scm *e, scm *a) { -#if DEBUG +#if 0//DEBUG printf ("\nc:loop e="); display (e); puts (""); diff --git a/mes.mes b/mes.mes index d17b99bc..6abf69d5 100644 --- a/mes.mes +++ b/mes.mes @@ -126,6 +126,7 @@ ((atom (car e)) (cond ((eq (car e) 'quote) (cadr e)) + ((eq (car e) 'lambda) e) ((eq (car e) 'unquote) (eval (cadr e) a)) ((eq (car e) 'quasiquote) (eval-quasiquote (cadr e) a)) ((eq (car e) 'cond) (evcon (cdr e) a)) diff --git a/test.mes b/test.mes index 43112e28..2c5e760c 100644 --- a/test.mes +++ b/test.mes @@ -100,10 +100,10 @@ (newline) (map display '(1 2 3 4)) (newline) -(map '(lambda (x) (display x) (newline)) '(5 6 7 8)) +(map (lambda (x) (display x) (newline)) '(5 6 7 8)) (newline) -(map '(lambda (i a) (display i) (display ':) (display a) (newline)) '(1 2 3 4) '(a b c d)) +(map (lambda (i a) (display i) (display ':) (display a) (newline)) '(1 2 3 4) '(a b c d)) (newline) '()