all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* defclass's :initarg weirdness
@ 2017-03-04  5:10 Andreas Politz
  0 siblings, 0 replies; only message in thread
From: Andreas Politz @ 2017-03-04  5:10 UTC (permalink / raw)
  To: emacs-devel


This is just a minor thing, but the macro defclass evaluates the
:initform form of it's attributes depending on the Lisp-form it has,
which is surprising.

#+BEGIN_SRC emacs-lisp
  ;; -*- lexical-binding : t -*-

  (defconst string "Hey, ho, let's go !")

  (defclass class1 nil
    ((attr :type string :initform string)))
  ;; => (invalid-slot-type attr string string)

  (defclass class2 nil
    ((attr :type string :initform (let nil string))))
  ;; => class2

  (let ((string "foo"))
    (defclass class3 nil
      ((attr :type string :initform (let nil string)))))

  (oref (make-instance 'class3) attr)
  ;; => "Hey, ho, let's go !"
#+END_SRC

The *Help* buffer does not mention this "weirdness", while the info
file is not helpful either.

,----[ (info "(eieio) Slot Options") ]
|      The value passed to initform used to be automatically quoted.
|      Thus,
|           :initform (1 2 3)
|      will use the list as a value.  This is incompatible with CLOS
|      (which would signal an error since 1 is not a valid function) and
|      will likely change in the future, so better quote your initforms if
|      they’re just values.
`----

Can this be changed to a lexically scoped evaluation at object creation
time ?  If not, it should at least be clearly stated in defclass's
documentation what the evaluation rules are.

-ap



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-03-04  5:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-04  5:10 defclass's :initarg weirdness Andreas Politz

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.