From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Joost Kremers Newsgroups: gmane.emacs.help Subject: Re: How does letf work? Date: 29 Jan 2014 09:14:38 GMT Message-ID: References: <52E838C8.5020101@miszellen.de> NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1390986915 2345 80.91.229.3 (29 Jan 2014 09:15:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 29 Jan 2014 09:15:15 +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 10:15:23 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 1W8REv-0001lM-OF for geh-help-gnu-emacs@m.gmane.org; Wed, 29 Jan 2014 10:15:21 +0100 Original-Received: from localhost ([::1]:41148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W8REs-0004qd-Ne for geh-help-gnu-emacs@m.gmane.org; Wed, 29 Jan 2014 04:15:18 -0500 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 29 Original-X-Trace: individual.net AYJlvDzf+s0SYGJUNqNzVAJ0EbxuFU1tPRB5a3Hbrw8RD0+i+e Cancel-Lock: sha1:UrroLd8wLSu9PCCikf2w625E3GY= Mail-Copies-To: nobody X-Editor: Emacs of course! User-Agent: slrn/pre1.0.0-18 (Linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:203479 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:95748 Archived-At: 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. 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. If it does, the object can stay around longer, as > demonstrated by returning the (cdr test-x). [Apologies for the reply-to-self...] This account also explains why the OP's code with setf works the way it does: (let ((x (copy-list test-x))) (setf (cdr x) '(a b c d)) x) => (KEY a b c d) 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). -- Joost Kremers joostkremers@fastmail.fm Selbst in die Unterwelt dringt durch Spalten Licht EN:SiS(9)