[Openmcl-devel] CLOS make-instance :around behaviour
hutch-lists at recursive.ca
Sun Oct 19 17:07:58 EDT 2008
On 19-Oct-08, at 4:46 PM, Pascal Costanza wrote:
> On 19 Oct 2008, at 22:40, Bob Hutchison wrote:
>> 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.
>> Better ideas?
> Stop using make-instance is not a bad idea. You could define your
> own create-instance function (or so), or shadow cl:make-instance in
> your own package to replace it with your own version.
Ohhh... Shadowing is an interesting idea... I'll check into it. Though
I suppose that it might be a little confusing.
> If the caching functionality is the only functionality you want to
> add, the CLOS MOP may be too big a weapon for this purpose.
Only the caching. I already had everything else in the initialize-
instance :after method.
> Are you sure that you need such caching? Garbage collectors are
> nowadays pretty good at recycling short-lived objects, so that you
> shouldn't need this for performance purposes - unless this is about
> semantics and not performance...
It's semantics I'm afraid. A simple situation is where there is a
cycle of objects -- only the id of the object is available to identify
that an object exists twice.
Yes, I agree, the GC is really quite good... and I take full advantage
of that elsewhere :-)
> 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