emacs-devel
[Top][All Lists]
Advanced

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

Re: force initialization of a datatype?


From: Dmitry Gutov
Subject: Re: force initialization of a datatype?
Date: Wed, 4 Nov 2015 21:17:17 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:42.0) Gecko/20100101 Thunderbird/42.0

On 11/04/2015 06:28 PM, Stephen Leake wrote:

(defun make-path-iterator (<user args>)
   (let ((result (vector 'cl-struct-path-iterator <slot values>)))
     <code to check the user args and set the slots in `result'>
     ))

This code compiles and runs correctly, but I'm wondering if it is
acceptable style. Is there a better way to accomplish this for
cl-defstruct?

Using `vector' looks wrong. I'm not too familiar with constructor syntax, but you can process each slot value before an instance gets constructed. See the example with &aux in http://www.gnu.org/software/emacs/manual/html_node/cl/Structures.html, or package-desc-from-define in package.el.

I'm not sure whether you can use a keyword argument with the same name as the slot, and convert the passed in value. That's something to try.

eieio defclass provides ":initform", which I'm guessing can specify a
function to run at object construction time, but I can't find any
definitive statement to that effect, neither in the Emacs info doc nor
via DuckDuckGo search. The lack of good documentation scares me away
from eieio in general.

If we're talking about xref, I think it would be generally good to migrate away from eieio in the core definitions. defstruct is lighter, and seems functional enough for our purposes.




reply via email to

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