help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: eieio defclass evaluate :initform value


From: Stefan Monnier
Subject: Re: eieio defclass evaluate :initform value
Date: Wed, 04 Jan 2017 17:43:37 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

> (defclass foo-class
>    ((bar :initform (lambda () my-var)
>          :type string)))

As the name implies, :initform expects a *form* rather than a function.
The above will simply initialize `bar` by default to have as value
a function of no arguments that returns the value of `my-var`.

> When make-instance was called, the lambda expression
> for :initform would be evaluated and the expression
> assigned to my-var would be used for the slot bar.

You can do

    (defclass foo-class ()
       ((bar :initform (progn my-var)
             :type string)))

[ For backward compatibility reasons, just using `my-var` doesn't work,
  because the EIEIO code treated symbols as unevaluated.  ]

> Is there nice way, in 24, to create a class with an :initform
> that, upon instantiation, evaluates to the value of a variable?
  
Does the above work for you?


        Stefan




reply via email to

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