I happened to find out the following discrepancy between DEFINE-SYNTAX and DEFINE-MACRO.
1. (define-syntax adbmal (syntax-rules () ((adbmal a ...) (lambda (f) (f a ...))) ((adbmal a ... . b) (lambda (f) (apply f a ... b))))) 2. (define-syntax adbmal (syntax-rules () ((adbmal "" (a ...) b . c) (adbmal "" (a ... b) . c)) ((adbmal "" (a ...)) (lambda (f) (f a ...))) ((adbmal "" (a ...) . b) (lambda (f) (apply f a ... b))) ((adbmal . a) (adbmal "" () . a)))) 3. (define (split-at-dot pair) ;(a b . c) => (c a b) (let loop ((tail pair) ;(a b c) => (() a b c) (head '())) (if (pair? tail) (loop (cdr tail) (cons (car tail) head)) (cons tail (reverse head))))) (define-macro (adbmal . rest) (let ((f (gensym)) (ls (split-at-dot rest))) (if (null? (car ls)) `(lambda (,f) (,f ,@rest)) `(lambda (,f) (apply ,f ,@(cdr ls) ,(car ls))))))
1,2: DEFINE-SYNTAX
(define a (list 10 20)) ((adbmal 1 2 a) list) => (1 2 (10 20)) ((adbmal 1 2 . a) list) => (1 2 10 20)
3: DEFINE-MACRO
(define a (list 10 20)) ((adbmal 1 2 a) list) => (1 2 (10 20)) ((adbmal 1 2 . a) list) => error -- Ill-formed special form: adbmal
PS: (a) I've not seen DEFINE-MACRO perform the above well in most implementations except BIGLOO & CL. (b) Even 2nd DEFINE-SYNTAX didn't work in some implementations. (c) I'd like to know whether the above DEFINE-SYNTAXs are illegal from a R5RS or R6RS point of view.
Thanks in advance.
Afficher les réponses par date