Re: Question about call-next-method

"pc (as pc at p-cos dot net)" <[email protected]>
Newsgroups gmane.lisp.lispworks.general
Message-ID <[email protected]>
Although the CLOS MOP specification is not binding, it is interesting to take a look at it to see what should be the case:

The entry for make-method-lambda states that by default, a method function is called with two arguments: a list of arguments to the generic function, and a list of next methods. Inside that method function, the local call-next-method function therefore can lexically close over that list of next methods.

Redefinition of methods (via defmethod or add-method) doesn’t change existing method metaobjects through side effects, but rather replaces them - so the methods in the list of next methods above will not be affected. Therefore, undefining or modifying methods should have no impact on a “captured” call-next-method.

However, it is definitely also true that not all Common Lisp implementations behave the same. For example, at least at some stage, Allegro Common Lisp was non-conforming (and I believe it still is): In their implementation, the list of next-methods is not passed as a (lexically scoped) argument to a method function, but rather bound to a dynamically scoped variable, which is rebound accordingly on each method function invocation. So in Allegro Common Lisp, you can therefore not rely on call-next-method to execute the same methods when invoked outside the dynamic extent of its definition. (It also makes it impossible in the general case to optimize tail calls in methods in Allegro Common Lisp.)

Again, the CLOS MOP specification is not binding, so I’m not claiming that Allegro Common Lisp is in any sort of violation here.

So it’s better to be very careful with non-obvious uses of call-next-method.

Pascal

> On 16 Nov 2025, at 15:26, Bradford Miller (as bradford dot w dot miller at gmail dot com) <[email protected]> wrote:
> 
> I think the real test would be what happens if you either undefine or modify the method it would have called, or add an extra more specific method that call-next-method would invoke had it been called afterwards. Does it act as it would if called now, or then? And are all “common lisps” the same?
> 
>> On Nov 16, 2025, at 6:55 AM, Tim Bradshaw (as tfb at cley dot com) <[email protected]> wrote:
>> 
>> On 16 Nov 2025, at 02:33, Edward Kiser (as edkiser at gmail dot com) <[email protected]> wrote:
>>> 
>>> The Common Lisp HyperSpec says, "The function call-next-method has
>>> lexical scope and indefinite extent, and can only be used within the
>>> body of a method defined by a method-defining form."
>> 
>> I think this is like saying that it's like a binding established by LET, (absent special declarations).  So yes, you can call it later if you've captured it.
>> 
>> _______________________________________________
>> Lisp Hug - the mailing list for LispWorks users
>> [email protected]
>> http://www.lispworks.com/support/lisp-hug.html
> 
> 
> _______________________________________________
> Lisp Hug - the mailing list for LispWorks users
> [email protected]
> http://www.lispworks.com/support/lisp-hug.html


_______________________________________________
Lisp Hug - the mailing list for LispWorks users
[email protected]
http://www.lispworks.com/support/lisp-hug.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.