From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nicolas Richard Newsgroups: gmane.emacs.tangents Subject: Re: 2016-05-23 Emacs News Date: Fri, 10 Jun 2016 12:30:23 +0200 Message-ID: <87twh1gwu8.fsf@members.fsf.org> References: <87lh30iv18.fsf@sachachua.com> <87bn39ewp6.fsf@linux-qg7d.fritz.box> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1465554965 6618 80.91.229.3 (10 Jun 2016 10:36:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 10 Jun 2016 10:36:05 +0000 (UTC) Cc: emacs-tangents@gnu.org To: Rolf Ade Original-X-From: emacs-tangents-bounces+get-emacs-tangents=m.gmane.org@gnu.org Fri Jun 10 12:35:55 2016 Return-path: Envelope-to: get-emacs-tangents@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 1bBJn8-0003Rm-QY for get-emacs-tangents@m.gmane.org; Fri, 10 Jun 2016 12:35:54 +0200 Original-Received: from localhost ([::1]:39648 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBJn7-0006p8-Qc for get-emacs-tangents@m.gmane.org; Fri, 10 Jun 2016 06:35:53 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43073) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBJhM-00024R-5F for emacs-tangents@gnu.org; Fri, 10 Jun 2016 06:29:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bBJhG-0005Yv-79 for emacs-tangents@gnu.org; Fri, 10 Jun 2016 06:29:55 -0400 Original-Received: from mxinc360.ulb.ac.be ([164.15.128.112]:3643 helo=mxin.ulb.ac.be) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBJhG-0005YX-0x for emacs-tangents@gnu.org; Fri, 10 Jun 2016 06:29:50 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoEIAEgeUlekD4Xx/2dsb2JhbABegmiBKH0BgnWjLAEBAQEIljEihXACggABAQEBAQFmJ4RGAQEEIw8BRhAIAxoCBSECAg8BRwYTGogVDrE/hUqLTwEBCAIBJIEBhF6FFYE5hgiCWQEEmEWGA4oKToQBgnuFaTWPHVSCFIFcOjKKEgEBAQ Original-Received: from mathsrv4.ulb.ac.be (HELO localhost) ([164.15.133.241]) by smtp.ulb.ac.be with ESMTP/TLS/AES128-SHA; 10 Jun 2016 12:29:48 +0200 User-agent: mu4e 0.9.17; emacs 25.0.92.1 In-reply-to: <87bn39ewp6.fsf@linux-qg7d.fritz.box> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 164.15.128.112 X-BeenThere: emacs-tangents@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-tangents-bounces+get-emacs-tangents=m.gmane.org@gnu.org Original-Sender: "Emacs-tangents" Xref: news.gmane.org gmane.emacs.tangents:130 Archived-At: Rolf Ade writes: > (That is: > http://mbork.pl/2016-05-23_Literal_values_and_destructive_functions) > > Wait, what? > > Sure, sort is documented as modifying the LIST in place. And the setq > makes `foo` global, so ... maybe no surprise, or so. But if I eval > > (defun destructive-havoc () > "Example of destructive havoc." > (let ((foo '(1 3 2))) > (message "before sort, foo is: %s" foo) > (sort foo #'<) > (message "after sort, foo is: %s" foo))) > > and M-: (destructive-havoc) two times, I still get > > before sort, foo is: (1 3 2) > after sort, foo is: (1 2 3) > before sort, foo is: (1 2 3) > after sort, foo is: (1 2 3) > > in *Messages*. Could someone please explain that to me? The article you're referring to explains just that. Is it somehow unclear ? Quoting the article: | What’s going on? | | Well, the literal in the function definition was actually changed. (If | you evaluate the defun form now, it will be redefined once again to | the “correct” value.) If you don’t believe it, try this: M-: | (symbol-function #'destructive-havoc), or even better, M-x | pp-eval-expression RET (symbol-function #'destructive-havoc) RET and | see for yourself. Btw it's even more impressive (imho) if you start from '(3 2 1) : (defun destructive-havoc () "Example of destructive havoc." (let ((foo '(3 2 1))) (message "before sort, foo is: %s" foo) (sort foo #'<) (message "after sort, foo is: %s" foo))) calling it twice gives : before sort, foo is: (3 2 1) after sort, foo is: (3) before sort, foo is: (3) after sort, foo is: (3) -- Nicolas