(FUNCTION MACRO-OR-SPECIAL-OPERATOR) at top-level doesn't throw an error.

Bug #841278 reported by Jean-Philippe Paradis on 2011-09-04
This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description

What I do and what happens:
#'multiple-value-bind ; Special operator

#'destructuring-bind ; Macro

(funcall #'destructuring-bind)
error -->
The function COMMON-LISP:DESTRUCTURING-BIND is undefined.
   [Condition of type UNDEFINED-FUNCTION]

What I expected to happen:
I expected a compile-time ERROR.

First of all the current behavior is indeed conforming, as CLHS FUNCTION (special operator) states:

"It is an error to use function on a function name that does not denote a function in the lexical environment in which the function form appears. Specifically, it is an error to use function on a symbol that denotes a macro or special form. An implementation may choose not to signal this error for performance reasons, but implementations are forbidden from defining the failure to signal an error as a useful behavior."

However I think it would be better to report this error at compile-time, as we don't want someone to try #'macro in the REPL and come to the conclusion that this is a valid way to get at the macro definition. In fact, here's a very similar situation that does report a compile-time ERROR:

(macrolet ((foo ()))
error -->
Compile-time error:
  found macro name FOO as the argument to FUNCTION

SBCL version: 1.0.51
uname -a: Linux dynamorph 2.6.32-33-generic #72-Ubuntu SMP Fri Jul 29 21:08:37 UTC 2011 i686 GNU/Linux


Nikodemus Siivola (nikodemus) wrote :

Though I'm marking this as triaged, I'm not sure if this should be WONTFIX instead. IIRC there is a good reason why we do things this way, but I can't remember it offhand right now.

Changed in sbcl:
importance: Undecided → Low
status: New → Triaged
Douglas Katzman (dougk) wrote :

There could not possibly be a "good" reason for this other than a slight performance win.
sb-fasteval doesn't have this behavior.
sb-eval does, mainly out of laziness - it does not check for macro-function (signaling an error), and then fdefinition if not a macro.
The simple evaluator (if no full eval implementation is built in) also exhibits the misbehavior.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers