On Tuesday, December 25, 2018 at 5:56:00 PM UTC-8, Kaz Kylheku wrote:
> On 2018-12-24, Spiros Bousbouras wrote:
> > "7.6.2 Introduction to Methods" says "A method object is not a function and
> > cannot be invoked as a function."
>
> That is defective; such wording should rarely appear in a language
> standard. It should be "a method object is of a distinct type from
> functions, and is not required to be invokable as a function".
Disagree. For consistency wouldn't you want similar language regarding
arrays, readtables, hashtables, and streams? There exist Lisp dialect
where some non-function objects are funcallable.
> That allows implementations to make it so callable if they want.
The ANS text you cite is no such prohibition, and is therefore only a
restriction on user programs. To be a prohibition on implementations
some language involving "an error ... signaled" would be necessary.
> > First I'm not clear if this is a
> > restriction on implementations i.e. a conforming implementation must not make
> > a method object FUNCALL-able ; or applications i.e. a portable application
>
> Bingo; it sure looks that way, and so why have such a constraint on
> what can be implemented.
>
> > cannot assume that a method object will be FUNCALL-able. Regardless , I would
> > imagine that every CL implementation implements methods as some kind of
> > closure so why restrict the possiblity to call them just like functions ?
The designers of CLOS realized that in some circumstances superior
performance would require hackery to the ways method functions are called,
or even whether they are called at all (so long as guaranteed semantics are
preserved). For example, real optimizations on real implementations optimize
slot accessor gfs so they operate via permutation tables and don't depend on
method functions working.
Also, method functions do not and cannot perform keyword argument checking
as if they were normal functions -- keyword arg checking can only be
and must be performed by the gf.
> They probably don't, though; methods could well be compiled into one big
> code blob in which they are just branches of code invoked by a case
> selection mechanism.
Reading the ANS as a strict standard, the method-function must exist, but it
has no required semantics if it is called by user code. That why the
arguments and environment in which method code is called is hidden inside
the CALL-METHOD macro [ANS]:
The macro call-method is used in method combination. It hides the
implementation-dependent details of how methods are called.
It's unfortunate that the text you complain about can and has led to
confusion about whether this is a prohibition on the implementation (it
isn't) but remember this ANS is intended only as a standard, not a tutorial,
and (by X3J13 consensus) can only be completely understood by gurus in
consideration of the entire ANS and in consideration with its exceptional
conditions conventions (Error Terminology, Conformance) yada yada yada...