[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Semantics of :initform and oset-default
From: |
Stefan Monnier |
Subject: |
Semantics of :initform and oset-default |
Date: |
Sun, 08 Feb 2015 21:48:16 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
Hi Eric,
I have some questions about the default values of object slots:
- The Texinfo docs say:
[...]
The value passed to initform is automatically quoted. Thus,
:initform (1 2 3)
appears as the specified list in the default object. A symbol that
[...]
this seems to say that :initform is really an init*value*. But then
in eieio-tests.el we have:
(defclass inittest nil
((staticval :initform 1)
(symval :initform eieio-test-permuting-value)
(evalval :initform (symbol-value 'eieio-test-permuting-value))
(evalnow :initform (symbol-value 'eieio-test-permuting-value)
:allocation :class)
)
"Test initforms that eval.")
(ert-deftest eieio-test-21-eval-at-construction-time ()
;; initforms that need to be evalled at construction time.
(setq eieio-test-permuting-value 2)
(setq eitest-pvinit (inittest))
(should (eq (oref eitest-pvinit staticval) 1))
(should (eq (oref eitest-pvinit symval) 'eieio-test-permuting-value))
(should (eq (oref eitest-pvinit evalval) 2))
(should (eq (oref eitest-pvinit evalnow) 1)))
which gives a different picture, and I don't really understand it: in
the `symval' slot the :initform seems to be quoted (as documented),
but in the other two (`evalval' and `evalnow') the :initforms are
actually evaluated.
- How is it supposed to interact with oset-default? Is the value passed
to `oset-default' interpreted as a plain value (to which the slot
will always be initialized), or is it interpreted as a "maybe
value maybe expression to be evaluated", like the :initform?
Stefan
- Semantics of :initform and oset-default,
Stefan Monnier <=