[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: force initialization of a datatype?
From: |
Stephen Leake |
Subject: |
Re: force initialization of a datatype? |
Date: |
Fri, 06 Nov 2015 05:56:33 -0600 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (windows-nt) |
Dmitry Gutov <address@hidden> writes:
> 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.
Thanks for the pointers.
> 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.
This works:
(cl-defstruct (path-iterator
(:constructor nil)
(:constructor make-path-iterator
(user-path &aux (path (path-iter-to-truename user-path))))
(:conc-name path-iter-)
(:copier nil))
path ;; user-path converted to absolute directory file truenames.
(defun path-iter-to-truename (path)
...)
However, `xref-find-definitions' doesn't find `make-path-iterator', and
there's no place to put a doc string for `make-path-iterator'.
I'll see if I can fix `xref-find-definitions'.
--
-- Stephe
- force initialization of a datatype?, Stephen Leake, 2015/11/04
- Re: force initialization of a datatype?, Dmitry Gutov, 2015/11/04
- Re: force initialization of a datatype?,
Stephen Leake <=
- Re: force initialization of a datatype?, Dmitry Gutov, 2015/11/06
- Re: force initialization of a datatype?, Stephen Leake, 2015/11/07
- Re: force initialization of a datatype?, Dmitry Gutov, 2015/11/07
- Re: force initialization of a datatype?, Stephen Leake, 2015/11/07
- Re: force initialization of a datatype?, Dmitry Gutov, 2015/11/07