From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Florian Beck Newsgroups: gmane.emacs.help Subject: Re: How does letf work? Date: Wed, 29 Jan 2014 16:29:56 +0100 Message-ID: <52E91E74.8060204@miszellen.de> References: <52E838C8.5020101@miszellen.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1391009836 32245 80.91.229.3 (29 Jan 2014 15:37:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 29 Jan 2014 15:37: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 Jan 29 16:37:24 2014 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 1W8XCd-00036u-5B for geh-help-gnu-emacs@m.gmane.org; Wed, 29 Jan 2014 16:37:23 +0100 Original-Received: from localhost ([::1]:43420 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W8XCc-0006RO-QE for geh-help-gnu-emacs@m.gmane.org; Wed, 29 Jan 2014 10:37:22 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54504) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W8XBT-00055m-JI for help-gnu-emacs@gnu.org; Wed, 29 Jan 2014 10:36:17 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W8XBN-0008LS-P8 for help-gnu-emacs@gnu.org; Wed, 29 Jan 2014 10:36:11 -0500 Original-Received: from mo6-p04-ob.smtp.rzone.de ([2a01:238:20a:202:5304::2]:56688) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W8XBN-0008LL-5N for help-gnu-emacs@gnu.org; Wed, 29 Jan 2014 10:36:05 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; t=1391009763; l=1436; s=domk; d=streitblatt.de; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:References: Subject:To:MIME-Version:From:Date:X-RZG-AUTH:X-RZG-CLASS-ID; bh=8544tCmant6uEw01Kg+B9cDBUcM=; b=SDOI8jxu7/dt9WbN727t0YKLF7Aejtlkg/YcUZlPWqmkd/WPFzo50JOqn6oIg8rpwkI JT2YpT/mXIAJgyUliGxWeubbWDFVaX4+SVcVmD9/cVgED9D73xwW8tXlTUmQLI5pVYEVu fG+3yqra2nyz0uK8vHlAGY7YI4K8oH5982A= X-RZG-CLASS-ID: mo04 X-RZG-AUTH: :KmALZ0mpdbGonPxw7gDkop508XQjelhLxGYn4B74/iddlkME3ssvHN/NVnKdtguvGeN0e0mu6uMa Original-Received: from [10.155.236.125] ([89.204.137.125]) by smtp.strato.de (RZmta 32.22 SBL|AUTH) with ESMTPSA id i04688q0TFTxTcx (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) for ; Wed, 29 Jan 2014 16:29:59 +0100 (CET) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a01:238:20a:202:5304::2 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:95753 Archived-At: Thanks for the answers! On 29.01.2014 10:14, Joost Kremers wrote: >> And since the printing is done outside the letf, as you pointed >> out, the object that's printed is the one pointed to by the global >> binding of test-x. Well, there is no local binding for test-x. As far as I understand what happens is this: (defvar test-x '(KEY 1 2 3 4)) (letf (((cdr test-x) '(a b c d))) test-x) This returns a pointer to test-x, but its cdr has been restored before the value is printed. >> But that's not because outside the letf the object created inside >> it is necessarily gone. It's gone because letf doesn't return a >> pointer to it. But it does return a pointer to test-x, which in turn pointed to the cdr. This is exactly what happens in the second example: (let ((x (copy-list test-x))) (setf (cdr x) '(a b c d)) x) > Because let creates a new binding (for x), a new pointer is created. > With copy-list, a new object is created to which this binding points. > After modifying the cdr of that object, the pointer is returned. > Outside the let, the binding for x is gone but the pointer to the > object it referred to is still alive, so the object itself is also > kept alive (until it's been printed). This makes sense. But it cannot be the whole story: (letf* ((x (copy-list test-x)) ((cdr x) '(a b c d))) x) => (KEY 1 2 3 4) I'm still confused. -- Florian Beck