diff --git a/GNUmakefile b/GNUmakefile index 739b5973..b06fbfe5 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -9,7 +9,7 @@ all: mes boot.mes check: all ./mes.test ./mes.test ./mes - ./mes < test.mes + cat scm.mes test.mes | ./mes boot.mes: mes.mes scm.mes test.mes cat $^ > $@ @@ -18,4 +18,4 @@ boot: all ./mes < boot.mes run: all - ./mes < test.mes + cat scm.mes test.mes | ./mes diff --git a/scm.mes b/scm.mes index 03ea9002..665007f6 100755 --- a/scm.mes +++ b/scm.mes @@ -21,6 +21,8 @@ ;; The Maxwell Equations of Software -- John McCarthy page 13 ;; http://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf +(define (list . rest) rest) + (define (scm-define x a) (cond ((atom (cadr x)) (cons (cadr x) (eval (caddr x) a))) (#t (cons (caadr x) (cons 'lambda (cons (cdadr x) (cddr x))))))) @@ -54,3 +56,27 @@ ;;(display 'loop:read-loop2-exiting...) ;;(newline) EOF + +(define (+ x y) (- x (- 0 y))) + +(define-macro (and x y) + (cond (x y) + (#t #f))) + +(define-macro (or x y) + (cond (x x) + (#t y))) + +(define (split-params bindings params) + (cond ((null bindings) params) + (#t (split-params (cdr bindings) + (append params (cons (caar bindings) '())))))) + +(define (split-values bindings values) + (cond ((null bindings) values) + (#t (split-values (cdr bindings) + (append values (cdar bindings) '()))))) + +(define-macro (let bindings . body) + (cons (cons 'lambda (cons (split-params bindings '()) body)) + (split-values bindings '()))) diff --git a/test.mes b/test.mes index 51b9342c..f7d5d9ea 100644 --- a/test.mes +++ b/test.mes @@ -35,23 +35,10 @@ (display (- 12 3)) (newline) -(define (+ x y) (- x (- 0 y))) (display (+ 3 4)) (newline) -(define-macro (and x y) - (cond (x y) - (#t #f))) - -(define-macro (or x y) - (cond (x x) - (#t y))) - -;; EOF2 -;; EOF -;; EOF2 - (display 'and-0-1:) (display (and 0 1)) (newline) @@ -66,39 +53,6 @@ (display (or #f 2)) (newline) -(define (split-params bindings params) - (cond ((null bindings) params) - (#t (split-params (cdr bindings) - (append params (cons (caar bindings) '())))))) - -(define (split-values bindings values) - (cond ((null bindings) values) - (#t (split-values (cdr bindings) - (append values (cdar bindings) '()))))) - -(define-macro (let1 bindings body) - (cons (cons 'lambda (cons (split-params bindings '()) (cons body '()))) - (split-values bindings '()))) - -(let1 ((a 3) - (b 4)) - ((lambda () - (display 'let-a:3-b:4) - (newline) - (display 'a:) - (display a) - (newline) - (display 'b:) - (display b) - (newline)))) - -(display 'let1-dun) -(newline) - -(define-macro (let bindings . body) - (cons (cons 'lambda (cons (split-params bindings '()) body)) - (split-values bindings '()))) - (let ((p 5) (q 6)) (display 'let-p:3-q:4)