mes.c: barf on unknown symbols.

This commit is contained in:
Jan Nieuwenhuizen 2016-07-23 11:51:06 +02:00
parent b8a7bb4486
commit b63444d919
3 changed files with 15 additions and 24 deletions

7
mes.c
View file

@ -309,7 +309,7 @@ eval (scm *e, scm *a)
if (e->type == SYMBOL) { if (e->type == SYMBOL) {
scm *y = assq (e, a); scm *y = assq (e, a);
if (y == &scm_f) { if (y == &scm_f) {
return e; //return e;
printf ("eval: no such symbol: %s\n", e->name); printf ("eval: no such symbol: %s\n", e->name);
assert (!"unknown symbol"); assert (!"unknown symbol");
} }
@ -1108,6 +1108,11 @@ mes_environment ()
{ {
scm *a = &scm_nil; scm *a = &scm_nil;
a = cons (cons (&scm_f, &scm_f), a);
a = cons (cons (&scm_nil, &scm_nil), a);
a = cons (cons (&scm_t, &scm_t), a);
a = cons (cons (&scm_unspecified, &scm_unspecified), a);
#include "environment.i" #include "environment.i"
return a; return a;

View file

@ -199,6 +199,8 @@
(set! counter (+ counter 1)) (set! counter (+ counter 1))
(string->symbol (string-append "g" value)))))) (string->symbol (string-append "g" value))))))
()
;; srfi-1 ;; srfi-1
(define (last-pair lst) (define (last-pair lst)
(let loop ((lst lst)) (let loop ((lst lst))

View file

@ -41,7 +41,7 @@
(display "mes:define-syntax...") (display "mes:define-syntax...")
(define-macro (mes:define-syntax macro-name transformer . stuff) (define-macro (define-syntax macro-name transformer . stuff)
`(define-macro (,macro-name . args) `(define-macro (,macro-name . args)
(,transformer (cons ',macro-name args) (,transformer (cons ',macro-name args)
(lambda (x) x) (lambda (x) x)
@ -63,7 +63,7 @@
(display "mes:define-syntax syntax-rules...") (display "mes:define-syntax syntax-rules...")
(newline) (newline)
(mes:define-syntax syntax-rules (define-syntax syntax-rules
(let () (let ()
(define name? symbol?) (define name? symbol?)
@ -242,25 +242,9 @@
(make-transformer rules)))) (make-transformer rules))))
(define-macro (define-syntax-rule id-pattern . template)
(mes:define-syntax mes:or `(define-syntax ,(car id-pattern)
(syntax-rules () (syntax-rules ()
((mes:or) #f) ((,(car id-pattern) . ,(cdr id-pattern)) ,@template))))
((mes:or e) e)
((mes:or e1 e ...) (let ((temp e1))
(cond (temp temp) (#t (or e ...)))))))
(display "(mes:or #f (= 0 1) 'hello-syntax-world): ") (define else #t)
(display (mes:or #f (= 0 1) 'hello-syntax-world))
(display (mes:or #f '==>baaa))
(newline)
(mes:define-syntax mes:when
(syntax-rules ()
((when condition exp ...)
(if condition
(begin exp ...)))))
(display (mes:when #t "when:hello syntax world"))
(newline)
'syntax-dun