define-syntax...
This commit is contained in:
parent
d53ea79a5d
commit
21a5e16a88
129
syntax.mes
129
syntax.mes
|
@ -1,22 +1,100 @@
|
|||
(define else #t)
|
||||
(define (syntax-error message thing)
|
||||
(display "syntax-error:")
|
||||
(display message)
|
||||
(display ":")
|
||||
;;(display thing)
|
||||
(newline))
|
||||
|
||||
(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
|
||||
;;(define (caddr x) (car (cdr (cdr x))))
|
||||
;; (define (caddr x)
|
||||
;; (display "wanna caddr:")
|
||||
;; (display x)
|
||||
;; (newline))
|
||||
|
||||
;; (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)))
|
||||
|
||||
;; (define (dinges form expander)
|
||||
;; (display "dinges form:")
|
||||
;; (display form)
|
||||
;; (newline)
|
||||
;; `(define-macro BOO ;;;,(cadr form)
|
||||
;; (let ((transformer ,(caddr form)))
|
||||
;; (lambda (form expander)
|
||||
;; (expander (transformer form
|
||||
;; (lambda (x) x)
|
||||
;; eq?)
|
||||
;; expander)))))
|
||||
|
||||
;; (define-macro (define-syntax form expander)
|
||||
;; `(expander (dinges form expander)
|
||||
;; expander))
|
||||
|
||||
(define-macro (define-syntax macro-name transformer . stuff)
|
||||
;; (display "define-syntax:")
|
||||
;; (newline)
|
||||
;; (display `(define-macro (,macro-name . args)
|
||||
;; (,transformer (cons ',macro-name args)
|
||||
;; (lambda (x) x)
|
||||
;; eq?)))
|
||||
;; (newline)
|
||||
`(define-macro (,macro-name . args)
|
||||
(
|
||||
,transformer (cons ',macro-name args)
|
||||
(lambda (x) x)
|
||||
eq?)
|
||||
expander))))
|
||||
expander)))
|
||||
eq?
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
;; (define-macro (define-syntax form expander)
|
||||
;; (expander `(define-macro ,(cadr form)
|
||||
;; (let ((transformer ,(caddr form)))
|
||||
;; (lambda (form expander)
|
||||
;; (expander (transformer form
|
||||
;; (lambda (x) x)
|
||||
;; eq?)
|
||||
;; expander))))
|
||||
;; expander))
|
||||
|
||||
;; (define-macro (define-syntax form expander)
|
||||
;; (expander `(define-macro ((cadr form) form expander)
|
||||
;; (let ((transformer (caddr form)))
|
||||
;; (expander (transformer form
|
||||
;; (lambda (x) x)
|
||||
;; eq?)
|
||||
;; expander)))
|
||||
;; expander))
|
||||
|
||||
(newline)
|
||||
|
||||
|
||||
(display "define-syntax when...")
|
||||
(display "define-syntax syntax-rules...")
|
||||
(newline)
|
||||
;; (define-macro (syntax-rules exp r c))
|
||||
|
||||
;; (define-syntax syntax-rules
|
||||
;; (let ()
|
||||
;; (lambda (exp r c)
|
||||
;; (display "hallo")
|
||||
;; (display "newline"))))
|
||||
|
||||
|
||||
;; (define-syntax syntax-rules
|
||||
;; (lambda (exp r c)
|
||||
;; (display "hallo")
|
||||
;; (display "newline")))
|
||||
|
||||
(define-syntax syntax-rules
|
||||
(let ()
|
||||
|
@ -70,7 +148,7 @@
|
|||
(meta-variables pattern 0 '())))))
|
||||
(syntax-error "ill-formed syntax rule" rule)))
|
||||
|
||||
; Generate code to test whether input expression matches pattern
|
||||
;; Generate code to test whether input expression matches pattern
|
||||
|
||||
(define (process-match input pattern)
|
||||
(cond ((name? pattern)
|
||||
|
@ -99,8 +177,8 @@
|
|||
,@conjuncts
|
||||
(loop (cdr l)))))))))
|
||||
|
||||
; Generate code to take apart the input expression
|
||||
; This is pretty bad, but it seems to work (can't say why).
|
||||
;; Generate code to take apart the input expression
|
||||
;; This is pretty bad, but it seems to work (can't say why).
|
||||
|
||||
(define (process-pattern pattern path mapit)
|
||||
(cond ((name? pattern)
|
||||
|
@ -120,7 +198,7 @@
|
|||
(process-pattern (cdr pattern) `(cdr ,path) mapit)))
|
||||
(else '())))
|
||||
|
||||
; Generate code to compose the output expression according to template
|
||||
;; Generate code to compose the output expression according to template
|
||||
|
||||
(define (process-template template rank env)
|
||||
(cond ((name? template)
|
||||
|
@ -187,7 +265,7 @@
|
|||
rank env free)))
|
||||
(else free)))
|
||||
|
||||
c ;ignored
|
||||
;;c ;ignored
|
||||
|
||||
;; Kludge for Scheme48 linker.
|
||||
;; `(cons ,(make-transformer rules)
|
||||
|
@ -196,13 +274,29 @@
|
|||
(make-transformer rules))))
|
||||
|
||||
|
||||
;; (define-syntax or
|
||||
;; (syntax-rules ()
|
||||
;; ((or) #f)
|
||||
;; ((or e) e)
|
||||
;; ((or e1 e ...) (let ((temp e1))
|
||||
;; (if temp temp (or e ...))))))
|
||||
|
||||
;; (define-syntax when
|
||||
;; (define-syntax xwhen
|
||||
;; (syntax-rules ()
|
||||
;; ((when condition exp ...)
|
||||
;; (if condition
|
||||
;; (begin exp ...)))))
|
||||
|
||||
;; (display "define-when: ")
|
||||
;; (display
|
||||
;; (define-syntax xwhen
|
||||
;; (syntax-rules ()
|
||||
;; ((when condition exp ...)
|
||||
;; (if condition
|
||||
;; (begin exp ...))))))
|
||||
;; (newline)
|
||||
;; (display (xwhen #t "hello syntax world"))
|
||||
|
||||
;; (define-macro (when cond exp . rest)
|
||||
;; `(if ,cond
|
||||
;; (begin ,exp . ,rest)))
|
||||
|
@ -211,3 +305,6 @@
|
|||
;; (define-macro (when clause . rest)
|
||||
;; (list 'cond (list clause (list 'let '() rest))))
|
||||
(newline)
|
||||
'boo
|
||||
EOF
|
||||
'()
|
||||
|
|
Loading…
Reference in a new issue