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: David Engster
Subject: Re: EIEIO built in methods -- question
Date: Mon, 10 Jun 2013 17:48:04 +0200
User-agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3 (gnu/linux)

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:

 -- Function: object-class obj
     Returns the class symbol from OBJ.

 -- Function: class-of obj
     CLOS symbol which does the same thing as `object-class'

If you could provide a doc-fix for the EIEIO section regarding CLOS
compatibility, that would be much appreciated, since you know much more
about CLOS than I do.

> So instead of using make-instance to get your persistent-things, use
> your own function that will test for singletons:
>
>
> (defvar *file-things-map* (make-hash-table :test (function equal)))
>
> (defun make-persistent-thing (&rest arguments)

[...]

Well, in some other OO languages, these singleton classes are usually
implemented through static members. AFAIK, in CLOS you also have these
in the form of slots with class allocation, which is also supported by
EIEIO. In fact, if you look at the eieio-singleton class, this is also
how it is implemented there.

So, I guess you could implement a more specific singleton which check
for the :file slot through something like this:

(defclass persistent-thing (eieio-persistent)
  ((allfiles :type list :initform nil
             :allocation :class)))

(defmethod constructor :static ((thing persistent-thing) name &rest slots)
  (let* ((filename (plist-get slots :file))
         (file->class (oref thing allfiles))
         (exist (cadr (assoc filename file->class)))
         newclass)
    (if exist
        exist
      (setq newclass (call-next-method))
      (setq file->class (append file->class
                                `((,filename ,newclass))))
      (oset-default thing allfiles file->class)
      newclass)))

Not as elegant as the "true CLOS-way", but it should work.

> But let's not critisize eieio authors.  AFAIK, they've just applied
> usual Agile directives, implementing an object system only to fulfill a
> very definite and limited goal, that of implementing cedet.  Their
> product manager never had a budget to schedule a sprint about
> implementing CLOS in emacs lisp.  The customer only wanted cedet, not
> CLOS (and if he wanted CLOS, he would know where to find it).

I guess you're speaking tongue in cheek here, still it should be
mentioned that there was no "they". It's pretty much all Eric Ludlam's
code, and I don't think agile directives were around in the mid
90's... :-)

@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.

-David




reply via email to

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