From: Stephen Leake <stephen_leake@stephe-leake.org>
To: emacs-devel@gnu.org
Subject: force initialization of a datatype?
Date: Wed, 04 Nov 2015 10:28:39 -0600 [thread overview]
Message-ID: <86lhadybig.fsf@stephe-leake.org> (raw)
I'm working on a type that should check the user provided
inititalization values, and I'm wondering if I can do that with
cl-defstruct, or if I should use eieio defclass instead.
I'd like to ensure that the only available constructors do the
checking.
Here's what I have come up with for cl-defstruct:
(cl-defstruct (path-iterator
(:constructor nil)
(:copier nil))
<slots>
)
(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?
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.
--
-- Stephe
next reply other threads:[~2015-11-04 16:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-04 16:28 Stephen Leake [this message]
2015-11-04 19:17 ` force initialization of a datatype? Dmitry Gutov
2015-11-06 11:56 ` Stephen Leake
2015-11-06 12:16 ` Dmitry Gutov
2015-11-07 7:05 ` Stephen Leake
2015-11-07 16:27 ` Dmitry Gutov
2015-11-07 18:30 ` Stephen Leake
2015-11-07 20:21 ` Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86lhadybig.fsf@stephe-leake.org \
--to=stephen_leake@stephe-leake.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.