[Openmcl-devel] CLOS make-instance :around behaviour
hutch-lists at recursive.ca
Mon Oct 20 07:21:51 PDT 2008
On 19-Oct-08, at 4:40 PM, Bob Hutchison wrote:
> On 19-Oct-08, at 3:33 PM, Pascal Costanza wrote:
>> You're invoking undefined consequences.
>> See Section 22.214.171.124.2 in the HyperSpec, bullet 19: You're defining
>> a method on a predefined generic function (make-instance) which is
>> applicable when its only required argument is a direct instance of
>> a standardized class (here the class 'symbol, of which 'some-class
>> is an instance: (typep 'some-class 'symbol) => T).
> Never would have found that :-) Thanks.
>> Common Lisp implementations are allowed to take that restriction
>> into account and, for example, compile away the call to make-
>> instance and replace it with something more efficient in case the
>> first argument is a constant symbol (for example).
>> If you really need :around methods on make-instance, consider
>> defining your own metaclass using the CLOS MOP. But based on your
>> example, I have the impression that an :after method on initialize-
>> instance should be sufficient, which is generally preferable
> That example is simplified. What I'm trying to do is implement a
> cache like thing. If someone calls, say, (make-instance 'thing :id
> "abc") then if there is already a thing with id "abc" return it
> rather than a new instance.
> As far as I know there's no way to change the return value of the
> primary method just using an :after method.
> So... I suppose either I define my own metaclass (a new adventure
> for me :-) or stop using make-instance.
I wound up defining my own metaclass. Jan Marecek gave me a nice head
start, and Closer to Mop makes it portable (thanks again Pascal).
This worked out quite nicely, with the exception that eql specializers
on methods don't work anymore. They aren't actually needed with the
new metaclass, so I didn't spend a lot of time trying to workout how
to get them working.
>> Lisp50: http://www.lisp50.org
>> Pascal Costanza, mailto:pc at p-cos.net, http://p-cos.net
>> Vrije Universiteit Brussel, Programming Technology Lab
>> Pleinlaan 2, B-1050 Brussel, Belgium
More information about the Openmcl-devel