help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EIEIO built in methods -- question


From: Eric Abrahamsen
Subject: Re: EIEIO built in methods -- question
Date: Tue, 11 Jun 2013 10:16:34 +0800
User-agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3 (gnu/linux)

David Engster <deng@randomsample.de> writes:

> Pascal J. Bourguignon writes:
>> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>>
>>> Specifically: Override the initialization method for a class that
>>> inherits from eieio-persistent, to make sure that it's impossible to
>>> create two instances of the class that have the same :file slot. I've
>>> already realized constructor is the wrong method, so probably
>>> initialize-instance.
>
> [...]
>
>> (class-of (make-instance 'c)) --> c                   ; in eieio
>> (class-of (make-instance 'c)) --> #<standard-class c> ; in CLOS
>
> [...]
>
>> and foremost, it lacks EQL specializers!
>
> These things should surely be documented in the manual (in the "CLOS
> compatibility" section). I'm not sure why `class-of' behaves this way;
> maybe it was to difficult to implement it the CLOS-way, or maybe Eric
> just did not know better. From reading the documentation, it seems he
> was thinking the class-of should return a name, since it says:

This discussion went over my head pretty fast! In my case I don't think
I need to worry about the behavior of `class-of', I was just looking to
tie some code into the creation of an object instance. Testing indicates
that this works perfectly well:

(defclass persisty (eieio-persistent)
  ())

(defmethod initialize-instance ((obj persisty) slots)
  (message "slots: %s" slots)
  (call-next-method obj slots))

I have access to `slots', can short-circuit initialization, and the
object is created as expected. Surely that's enough?

I like the idea of keeping the full list of files in a class-allocated
slot. If it's a problem that the slot only exists after the first
instance has been created, that seems like something that can be
accounted for in `initialize-instance' as well...

One thing I'm still confused about (and if I'm going to provide a doc
patch, this is exactly what I'd like to address) is the relationship
between `constructor', `initialize-instance' and `shared-initialize'.
Obviously I can see that they call each other in that order, but I don't
understand when you'd want to override one vs the other. As far as I can
tell the only difference is that `constructor' has access to the string
object name (the point of which I've never understood), and
`initialize-instance' doesn't.

Actually, thinking about this further, I should probably be using
:after on my initialize-instance method above, to give the
default superclass method a chance to assign any dynamically evaluated
slot values. Or not? These are the questions I'm hoping to get answered.

[...]

> @Eric: If you'd like to improve the documentation, that would be much
> appreciated. I would definitely read over it, but I'm no expert in
> EIEIO, so it'd be best if you could send your contributions to
> emacs-devel or submit it as a bug report, so that others can also check
> it.

Thanks for the offer! It would be something simple, just about using
`initialize-instance', `constructor' if I ever understand exactly what
that does, `object-print', and a few other methods in that neighborhood.
As I mentioned I'm coming at this from Python experience, and wanted to
write a basic how-to that would make sense to people with OO experience
in other languages.

Thanks
Eric




reply via email to

[Prev in Thread] Current Thread [Next in Thread]