Opened 6 years ago

Last modified 6 years ago

#1253 new defect

Conformance issue with compiler macros and FUNCALL

Reported by: Bike Owned by:
Priority: minor Milestone:
Component: ANSI CL Compliance Version: trunk
Keywords: macro compiler compiler-macro Cc:

Description (last modified by rme)

define-compiler-macro is specified to work on funcall forms:

"The &whole argument is bound to the form argument that is passed to the compiler macro function. The remaining lambda-list parameters are specified as if this form contained the function name in the car and the actual arguments in the cdr, but if the car of the actual form is the symbol funcall, then the destructuring of the arguments is actually performed using its cddr instead. "

As demonstrated in the CLHS example:

(define-compiler-macro square (x) ...)
(funcall (compiler-macro-function 'square) '(funcall #'square x) nil) => (EXPT X 2)

This does not work on CCL:

(funcall (compiler-macro-function 'square) '(funcall #'square x) nil)
(#'SQUARE X) can't be destructured against the lambda list (ARG), because it contains 2 elements, and exactly one are expected.             
   [Condition of type CCL::SIMPLE-PROGRAM-ERROR]

CCL presumably doesn't try to compiler-macroexpand funcall forms, so this error doesn't come up during compilation, but the CLHS is still pretty clear that c-m-fs should work on funcall forms regardless. (Also, CCL actually trying to compiler macroexpand funcall forms might help optimization.)

I have a library that's pedantic enough to define a parse-compiler-macro that works around this issue using a very bad code walker that relies on CCL internal symbols. I would like to not do this.

A fix would essentially amount to changing parse-macro to know whether it's being used for defmacro or define-compiler-macro, and if it's the latter, changing a (cdr form) to (if (eql (car form) 'funcall) (cddr form) (cdr form)) or the like.

Change History (1)

comment:1 Changed 6 years ago by rme

  • Description modified (diff)
Note: See TracTickets for help on using tickets.