#5 define-macro wrong when defiand is symbol

Tom Breton

When define-macro is given a defiand that is a symbol to be define as a lambda form, like:

(define-macro buggy-1
(lambda (vv g) ''whatever))

the resulting definition treats its arguments wrong, as the attached script demonstrates. It is as if the first argument binds to the whole form, like '(buggy-1 arg arg)
The existence of the second argument just results in "Error: not enough arguments".

I note that macro-expand expands the above to

(macro buggy-1 (lambda (vv g) ''whatever))

while it expands (the correctly-working):

(define-macro (not-buggy-1 vv g) ''works)

quite differently:

(macro (not-buggy-1 gensym-5) (apply (lambda (vv g) ''works) (cdr gensym-5)))

I am unsure whether the first expansion should be expected to work or not, so I haven't volunteered a fix of macro-expand until that's clear to me.


  • Tom Breton

    Tom Breton - 2006-12-23

    Script to show the results of the bug

  • Nobody/Anonymous

    Logged In: NO

    ;;It is DEFINE-MACRO corresponding to the buggy-1 form.
    (macro (define-macro dform)
    (let ((form (gensym)))
    (if (symbol? (cadr dform))
    `(macro (,(cadr dform) ,form) (apply ,@(caddr dform) (cdr ,form)))
    `(macro (,(caadr dform) ,form)
    (apply (lambda ,(cdadr dform) ,@(cddr dform)) (cdr ,form))))))


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks