%coerce-callable-to-fun lack of error checking sometimes
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
New
|
Undecided
|
Unassigned |
Bug Description
SYMBOL-FUNCTION (and fdefinition) is specified to return an arbitrary implementation-
Historically SBCL (and CMUCL) return a function which when called complains that it's not really a function. A consequence of that choice is that an error is almost never trapped if no funcall occurs, such as in:
* (mapcar (symbol-function 'throw) '())
NIL
* (mapcar (symbol-function 'and) '())
NIL
Most other lisps return a magic value from symbol-function. We could do that also.
The desired outcome is that there is no extra cost to rejecting macros wherever the compiler has optimized a higher-order function to using %coerce-callable eagerly (i.e. before trying an actual funcall). We definitely don't want %coerce-callable to check some arbitrary property of the specified function to see if it's really supposed to be called. (We do that if the arg to %coerce-to-callable was a symbol, but in that event it already costs something to lookup the function)
It may work to have macros and symbols look internally like un-fboundp symbols, and also impart behavior to symbol-function, fdefinition, fboundp that don't signal an error. This would fix the %coerce-callable situation efficiently.
Granted it's only a problem for sequence traversal operations on empty sequences. Maybe there are some other situations, but this caught my attention.
It's kinda similar to (mapcar 'car nil nil) not signaling an error because it's never applied. The standard says it returns an implementation defined value, and returning a function is such a value. Then it's valid to pass functions to mapcar.
So, it's not a standard compliance nor a safety issue, just catching bad values early.