emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

defclass's :initarg weirdness


From: Andreas Politz
Subject: defclass's :initarg weirdness
Date: Sat, 04 Mar 2017 06:10:32 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]