Re: [CLOS] Ensuring a method exists



Ken Tilton wrote:

Now maybe that is what is going on and the OP is just leveraging CLOS as a convenient internal tool to the larger API, but then that is why I suggest going /further/ and hide the CLOS behind some macrology, at which point the OP can enforce anything they want really really easily (instead of staring at AMOP looking for support for something not really OO-able).

Both macros and the CLOS MOP are means to do metaprogramming. The distinction is that macros can be used for compile-time processing of code [1], while the CLOS MOP is useful for meta-programs that require special actions at runtime. Of course, it is always possible to make macros generate the code that takes care of the runtime issues, but it can be more convenient to rely on the MOP protocols, especially if you want to reuse major parts of the already existing functionality in CLOS.

Didier's example is actually a good one for the latter because you can delay the check whether methods are "properly" specialized until the latest possible stage, something that is not very easy to achieve with macros. That's similar to deferring class precedence lists, or the update protocols for changed or redefined classes, etc.


Pascal

[1] More correctly, "processing of code at macroexpansion time", but for most practical purposes, that's the same as compile time.

--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
.



Relevant Pages

  • Re: [CLOS] Ensuring a method exists
    ... CLOS as a convenient internal tool to the larger API, but then that is why I suggest going /further/ and hide the CLOS behind some macrology, at which point the OP can enforce anything they want really really easily. ... Both macros and the CLOS MOP are means to do metaprogramming. ... What parameters does a macro function take, and what does it eventually return? ... And your sketch of a solution doesn't yet deal with doing the check only once for each list of specializers. ...
    (comp.lang.lisp)
  • Re: [CLOS] Ensuring a method exists
    ... Both macros and the CLOS MOP are means to do metaprogramming. ... special actions at runtime. ... Macros can expand to code that gets run at load time, which code records (say, in, symbol properties) information to be used by runtime code, such as an around method to check that a method has been defined for the specific types of the arguments. ...
    (comp.lang.lisp)
  • Re: [CLOS] Ensuring a method exists
    ... Pascal Costanza wrote: ... CLOS as a convenient internal tool to the larger API, but then that is why I suggest going /further/ and hide the CLOS behind some macrology, at which point the OP can enforce anything they want really really easily. ... Both macros and the CLOS MOP are means to do metaprogramming. ... You _always_ use macros for compile-time processing of code. ...
    (comp.lang.lisp)
  • Re: [CLOS] Ensuring a method exists
    ... CLOS as a convenient internal tool to the larger API, but then that is why I suggest going /further/ and hide the CLOS behind some macrology, at which point the OP can enforce anything they want really really easily. ... Both macros and the CLOS MOP are means to do metaprogramming. ... You _always_ use macros for compile-time processing of code. ...
    (comp.lang.lisp)
  • Re: Non-congruent Lambda Lists in CLOS
    ... The CLOS MOP specifies the runtime behavior of CLOS, and as such it could actually be made to work. ... However, ANSI Common Lisp allows CL compilers to check method congruency already at compile time, independent of what the involved generic function classes or the method classes are, and the CLOS MOP doesn't provide any means to switch off such compile-time checks. ... Situations" entries for defgeneric and defmethod state that method lambda lists must be congruent to the respective generic function lambda list, or otherwise an error is signaled ...
    (comp.lang.lisp)

Quantcast