From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Eric Ludlam <eric@siege-engine.com>
Cc: "Eric M. Ludlam" <zappo@gnu.org>, emacs-devel@gnu.org
Subject: Re: Semantics of :initform and oset-default
Date: Mon, 09 Feb 2015 09:56:14 -0500 [thread overview]
Message-ID: <jwv1tlzuool.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <54D8B0CD.1020703@siege-engine.com> (Eric Ludlam's message of "Mon, 09 Feb 2015 08:06:21 -0500")
> It was pointed out that the initform is supposed to be evaluated so there
> is a bit of a hybrid behavior which allows:
Ah, the historical account is quite helpful: now the weird hack makes
a lot more sense.
> A slot with :allocation :instance (the default) would have the form
> evaluated when it is constructed. A slot with :allocation :class is
> evaluated when the class is created. If just the symbol is in there, it
> acts as a constant value (ie - no function form to call)
Yes, this is the standard CLOS behavior, indeed.
ELISP> (setq moose 1)
> 1
ELISP> (oset-default 'foo test '(symbol-value 'moose))
> (symbol-value 'moose)
ELISP> (foo "hi")
> [object foo "hi" 1]
Yuck! You just forced EIEIO to use runtime code generation (since it
had to turn the (symbol-value 'moose) list into a chunk of code).
> I don't know if that is correct or not. It didn't occur to me that you
> could do that until I tried explaining just now.
Hmm... I wonder if someone relies on this misfeature.
> Here is the documentation I had used at the time:
> http://www.lispworks.com/documentation/HyperSpec/Body/m_defcla.htm
Yes, this describes the :initform semantics, but not its interaction
with `oset-default' since CLOS doesn't have anything like
`oset-default'.
> It goes on to talk about the lexical environment which I didn't/don't know
> how to deal with.
It's easy: turn every initform in the defclass definition into a lambda
expression and store that (i.e. a closure instead of a "form") into the
class's slot descriptor. Then, instead of `eval', use `funcall' in
(the equivalent of) eieio-default-eval-maybe.
Stefan "Every time you have to use `eval', a baby cries"
next prev parent reply other threads:[~2015-02-09 14:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-09 2:48 Semantics of :initform and oset-default Stefan Monnier
2015-02-09 13:06 ` Eric Ludlam
2015-02-09 14:56 ` Stefan Monnier [this message]
2015-02-10 0:27 ` Eric Ludlam
2015-02-10 2:47 ` Stefan Monnier
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=jwv1tlzuool.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@gnu.org \
--cc=eric@siege-engine.com \
--cc=zappo@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.