syntax.mes: experiments...

This commit is contained in:
Jan Nieuwenhuizen 2016-07-16 07:56:50 +02:00
parent cf0c3ef42e
commit 08b1a52af2

94
syntax.mes Normal file
View file

@ -0,0 +1,94 @@
(display "define-syntax...")
(define-macro define-syntax
(lambda (form expander)
(expander `(define-macro ,(cadr form)
(let ((transformer ,(caddr form)))
(lambda (form expander)
(expander (transformer form
(lambda (x) x)
eq?)
expander))))
expander)))
(newline)
(display "define-syntax when...")
;; (define-syntax when
;; (syntax-rules ()
;; ((when condition exp ...)
;; (if condition
;; (begin exp ...)))))
;; (define-macro (when cond exp . rest)
;; `(if ,cond
;; (begin ,exp . ,rest)))
(define-macro (when clause . rest)
(cond
((not (eq? clause #f)) (cons 'let (cons '() rest)))))
(define-macro (ifwhen clause . rest)
(if (not (eq? clause #f)) (cons 'let (cons '() rest))))
(define-macro my-when
(lambda (test . branch)
(list 'if test (cons 'begin branch))))
;; (define-macro (q-when test . branch)
;; `(if ,test
;; (begin ,@branch)))
;; (define-macro (when clause exp . rest)
;; (display "all=")
;; (display (cons exp rest))
;; (newline)
;; `(if ,clause
;; (begin ,(cons exp rest))))
;; (define-macro (when clause . rest)
;; (cond
;; ((not (eq? clause #f)) (cons 'let (cons '() rest)))))
(newline)
(ifwhen #t
(display "true")
(newline))
(ifwhen #f
(display "false")
(newline)
'())
(my-when #t
(display "my-when")
(newline)
'())
;; (q-when #t
;; (display "q-when")
;; (newline)
;; '())
(define *gensym* 0)
(define (gensym)
(set! *gensym* (+ *gensym* 1))
(string->symbol (string-append "g" (number->string *gensym*))))
(define-macro bla (gensym))
(display bla) (newline)
(display bla) (newline)
(display bla) (newline)
(newline)
'()
;;EOF
EOF2