From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Semantics of :initform and oset-default Date: Mon, 09 Feb 2015 09:56:14 -0500 Message-ID: References: <54D8B0CD.1020703@siege-engine.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1423493806 26719 80.91.229.3 (9 Feb 2015 14:56:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 9 Feb 2015 14:56:46 +0000 (UTC) Cc: "Eric M. Ludlam" , emacs-devel@gnu.org To: Eric Ludlam Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Feb 09 15:56:45 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YKplU-000408-Er for ged-emacs-devel@m.gmane.org; Mon, 09 Feb 2015 15:56:44 +0100 Original-Received: from localhost ([::1]:33319 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKplT-0002cU-V6 for ged-emacs-devel@m.gmane.org; Mon, 09 Feb 2015 09:56:43 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55025) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKpl8-0002DJ-Rb for emacs-devel@gnu.org; Mon, 09 Feb 2015 09:56:23 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YKpl7-0006Sf-RV for emacs-devel@gnu.org; Mon, 09 Feb 2015 09:56:22 -0500 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:44685) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKpl3-0006Rc-BR; Mon, 09 Feb 2015 09:56:17 -0500 Original-Received: from pastel.home (lechon.iro.umontreal.ca [132.204.27.242]) by pruche.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id t19EuFSU029243; Mon, 9 Feb 2015 09:56:15 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id 2A37E1240; Mon, 9 Feb 2015 09:56:15 -0500 (EST) In-Reply-To: <54D8B0CD.1020703@siege-engine.com> (Eric Ludlam's message of "Mon, 09 Feb 2015 08:06:21 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV5212=0 X-NAI-Spam-Version: 2.3.0.9393 : core <5212> : inlines <2054> : streams <1387400> : uri <1850533> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 132.204.246.22 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:182694 Archived-At: > It was pointed out that the initform is supposed to be evaluated so there > is a bit of a hybrid behavior which allows: Ah, the historical account is quite helpful: now the weird hack makes a lot more sense. > A slot with :allocation :instance (the default) would have the form > evaluated when it is constructed. A slot with :allocation :class is > evaluated when the class is created. If just the symbol is in there, it > acts as a constant value (ie - no function form to call) Yes, this is the standard CLOS behavior, indeed. ELISP> (setq moose 1) > 1 ELISP> (oset-default 'foo test '(symbol-value 'moose)) > (symbol-value 'moose) ELISP> (foo "hi") > [object foo "hi" 1] Yuck! You just forced EIEIO to use runtime code generation (since it had to turn the (symbol-value 'moose) list into a chunk of code). > I don't know if that is correct or not. It didn't occur to me that you > could do that until I tried explaining just now. Hmm... I wonder if someone relies on this misfeature. > Here is the documentation I had used at the time: > http://www.lispworks.com/documentation/HyperSpec/Body/m_defcla.htm Yes, this describes the :initform semantics, but not its interaction with `oset-default' since CLOS doesn't have anything like `oset-default'. > It goes on to talk about the lexical environment which I didn't/don't know > how to deal with. It's easy: turn every initform in the defclass definition into a lambda expression and store that (i.e. a closure instead of a "form") into the class's slot descriptor. Then, instead of `eval', use `funcall' in (the equivalent of) eieio-default-eval-maybe. Stefan "Every time you have to use `eval', a baby cries"