From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: About `setf' with macro call Date: Wed, 17 Apr 2013 16:06:42 +0200 Message-ID: <87fvypi74d.fsf@thinkpad.tsdh.de> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1366207636 29376 80.91.229.3 (17 Apr 2013 14:07:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 17 Apr 2013 14:07:16 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Apr 17 16:07:19 2013 Return-path: Envelope-to: geh-help-gnu-emacs@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 1UST13-0001L8-Dv for geh-help-gnu-emacs@m.gmane.org; Wed, 17 Apr 2013 16:07:17 +0200 Original-Received: from localhost ([::1]:37486 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UST12-0007IJ-Un for geh-help-gnu-emacs@m.gmane.org; Wed, 17 Apr 2013 10:07:16 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:39438) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UST0q-000795-SY for help-gnu-emacs@gnu.org; Wed, 17 Apr 2013 10:07:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UST0i-0006G2-Iw for help-gnu-emacs@gnu.org; Wed, 17 Apr 2013 10:07:04 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:60626) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UST0i-0006Fa-Cu for help-gnu-emacs@gnu.org; Wed, 17 Apr 2013 10:06:56 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UST0e-0000pr-FT for help-gnu-emacs@gnu.org; Wed, 17 Apr 2013 16:06:52 +0200 Original-Received: from tsdh.uni-koblenz.de ([141.26.67.142]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 17 Apr 2013 16:06:52 +0200 Original-Received: from tsdh by tsdh.uni-koblenz.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 17 Apr 2013 16:06:52 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 71 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: tsdh.uni-koblenz.de User-Agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.3.50 (gnu/linux) Cancel-Lock: sha1:UbAb39LUgKtPYz385DL6+vamMPo= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 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-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:90205 Archived-At: xfq writes: > In (info "(cl) Setf Extensions"), there is a example about using `setf' > on a macro call: > > (defmacro wrong-order (x y) (list 'aref y x)) > (setf (wrong-order A B) 17) > > I evaluated these two expressions, and debugger entered: > > Debugger entered--Lisp error: (void-variable B) > (let* ((v B) (v A)) (aset v v 17)) > (setf (wrong-order A B) 17) > eval((setf (wrong-order A B) 17) nil) > eval-last-sexp-1(nil) > eval-last-sexp(nil) > call-interactively(eval-last-sexp nil nil) > command-execute(eval-last-sexp) > > I understand that `A' and `B' are two invalid S-expressions here. But > I don't understand the `let*' expression in the backtrace. You need to have a look at the macro expansions to understand the problem. --8<---------------cut here---------------start------------->8--- ELISP> (macroexpand '(wrong-order A B)) (aref B A) ELISP> (macroexpand '(setf (wrong-order A B) 17)) (let* ((v B) (v A)) (aset v v 17)) --8<---------------cut here---------------end--------------->8--- Now that explains the let* in the backtrace, but the setf-expansion looks totally wrong! v is set to B (the index) and then overridden by A (the array). So aset becomes called with the array, the array again in place where the index should be, and then the value to be set... Let's try it with an example: --8<---------------cut here---------------start------------->8--- ELISP> (defvar my-array (make-vector 10 1)) my-array ELISP> my-array [1 1 1 1 1 1 1 1 1 1] ELISP> (setf (aref my-array 4) 3) 3 ELISP> my-array [1 1 1 1 3 1 1 1 1 1] ELISP> (setf (wrong-order 4 my-array) 17) 17 ELISP> my-array [1 1 1 1 17 1 1 1 1 1] --8<---------------cut here---------------end--------------->8--- Strange. Although the macro expansion looks broken, it works anyhow?! Now let's test the macro expansion manually. --8<---------------cut here---------------start------------->8--- ELISP> (let* ((v 4) (v my-array)) (aset v v 19)) *** Eval error *** Wrong type argument: integerp, [1 1 1 1 17 1 1 1 1 1] --8<---------------cut here---------------end--------------->8--- Yes, that's what I expected also from the macro version... Can anyone explain what's going on here? Bye, Tassilo