From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: eieio defclass evaluate :initform value Date: Wed, 04 Jan 2017 17:43:37 -0500 Message-ID: References: <20170104120403.6e7c67e8@gauss> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1483571015 13953 195.159.176.226 (4 Jan 2017 23:03:35 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 4 Jan 2017 23:03:35 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jan 05 00:03:30 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cOuaS-0001I1-IA for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Jan 2017 00:03:16 +0100 Original-Received: from localhost ([::1]:42678 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cOuaU-0004mc-Pa for geh-help-gnu-emacs@m.gmane.org; Wed, 04 Jan 2017 18:03:18 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55975) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cOuHs-0005Co-4C for help-gnu-emacs@gnu.org; Wed, 04 Jan 2017 17:44:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cOuHo-0004oO-8X for help-gnu-emacs@gnu.org; Wed, 04 Jan 2017 17:44:04 -0500 Original-Received: from [195.159.176.226] (port=60508 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cOuHo-0004o1-15 for help-gnu-emacs@gnu.org; Wed, 04 Jan 2017 17:44:00 -0500 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1cOuHW-0002zP-CV for help-gnu-emacs@gnu.org; Wed, 04 Jan 2017 23:43:42 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 28 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:zqPzZ8VsutHp3qgQL3fTXqHdhGY= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-Mailman-Approved-At: Wed, 04 Jan 2017 17:59:48 -0500 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:112053 Archived-At: > (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