#5 define-macro wrong when defiand is symbol

open
nobody
None
5
2006-12-23
2006-12-23
Tom Breton
No

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.

Discussion

  • Tom Breton
    Tom Breton
    2006-12-23

    Script to show the results of the bug

     
    Attachments
  • 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))))))