From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kelly Dean Newsgroups: gmane.emacs.help Subject: Re: Is add-to-list supposed to work when lexical-binding is t? Date: Wed, 5 Jun 2013 16:12:09 -0700 (PDT) Message-ID: <1370473929.92379.YahooMailClassic@web141101.mail.bf1.yahoo.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1370473960 30632 80.91.229.3 (5 Jun 2013 23:12:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 5 Jun 2013 23:12:40 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jun 06 01:12:39 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 1UkMse-0007HO-EK for geh-help-gnu-emacs@m.gmane.org; Thu, 06 Jun 2013 01:12:36 +0200 Original-Received: from localhost ([::1]:36092 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkMsd-0005e4-TK for geh-help-gnu-emacs@m.gmane.org; Wed, 05 Jun 2013 19:12:35 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54437) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkMsM-0005du-5C for help-gnu-emacs@gnu.org; Wed, 05 Jun 2013 19:12:24 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UkMsF-0002IE-SH for help-gnu-emacs@gnu.org; Wed, 05 Jun 2013 19:12:18 -0400 Original-Received: from nm15-vm0.bullet.mail.bf1.yahoo.com ([98.139.212.254]:36956) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkMsF-0002Hz-O7 for help-gnu-emacs@gnu.org; Wed, 05 Jun 2013 19:12:11 -0400 Original-Received: from [98.139.212.146] by nm15.bullet.mail.bf1.yahoo.com with NNFMP; 05 Jun 2013 23:12:10 -0000 Original-Received: from [98.139.215.229] by tm3.bullet.mail.bf1.yahoo.com with NNFMP; 05 Jun 2013 23:12:10 -0000 Original-Received: from [127.0.0.1] by omp1069.mail.bf1.yahoo.com with NNFMP; 05 Jun 2013 23:12:10 -0000 X-Yahoo-Newman-Property: ymail-5 X-Yahoo-Newman-Id: 542896.2357.bm@omp1069.mail.bf1.yahoo.com Original-Received: (qmail 2725 invoked by uid 60001); 5 Jun 2013 23:12:10 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1370473929; bh=W2c32mqm7QFKsOc2wALqQ8DgJzpU0LRU7R/FTsp5REA=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:Message-ID:Date:From:Subject:To:MIME-Version:Content-Type; b=Efc3hVJaJ9KBXSHk4LwjNXTUXlRDEasIHLUVZc1V9dt1Ek0GDY/TnhGVuqQgHe9Jsn6lgFYVZOptGi+3KRdfasvwVJZt84JZc2oF+fIxr5Hh9pmvkQmghplPEu60MK4a94694aWUlXmHcXsP7Ff3iVAx8tL3LlEcgjionewzqno= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:Message-ID:Date:From:Subject:To:MIME-Version:Content-Type; b=S3z/tvCvfwE2/BDnLpSqAV3b7babPg/DK2HZf3Qc3FlMHSZhP1EgncEw2kt6nRu16oeZBQp1mMl1xSL69zjDkSG/+jy4WhwnEunBvkl49fJpXBMsIZNHMUZt54FA72Z1EEqrmmMtuPJHZkVT0d/143HqF8HeVeCKMpE3an+XrP0=; X-YMail-OSG: hldxLO8VM1nKRJdAYHJ_cuQUyXYqc7epVZhF7cNt568RHTz JtPof3rs3WNYi2WbFMs6Runr.9v22px_2Xl5AwC6D22IVQQsQj0spbOffgPM 4zsjVxJ6O4HSn8pORuBdJNB.JzeuKgxJeBTRSbdaKNHE9K9UhZdNxUid0w6E XPARcy4jbyMdqtvi.N_Ll7wZwhDuDZBCHuFpmxXC7KWyqZ335KflS5fbrUzl oqHPUt5DsAGdcXcfk.HjL8g8y6W3eIA6tSIA0qwkNDLq5I5AoBLmxi46liRj OUWANKWrvXcb9Ar4FWRuZXvWWBnDCKHYIyjv8AUqq7zF01qUegYsp2svzJss etTtT4aKJxACw8VJp4JV0AOaVBjbR8FSGpICeokE.LEUm7uofFLLkTTh3Ei9 INV5zNJBrXeIRAgzF4Qg4JDkKYL7bjAXyPFBwXmYXVAqjurQ5TWhh4pfJomA xkN12HIavCgKJGPg3mxYAnHLSUxq3MEQXd_Z.Nhezg5HM Original-Received: from [87.236.194.191] by web141101.mail.bf1.yahoo.com via HTTP; Wed, 05 Jun 2013 16:12:09 PDT X-Rocket-MIMEInfo: 002.001, U3RlZmFuIE1vbm5pZXIgd3JvdGU6Cj4.IFNlY3Rpb24gMTEuOS4zIChMZXhpY2FsIEJpbmRpbmcpIGluIHRoZSBtYW51YWwgc2F5cyAiZnVuY3Rpb25zIGxpa2UKPj4gYHN5bWJvbC12YWx1ZScsIGBib3VuZHAnLCBhbmQgYHNldCcgb25seSByZXRyaWV2ZSBvciBtb2RpZnkKPj4gYSB2YXJpYWJsZSdzIGR5bmFtaWMgYmluZGluZyIuICBXaHk_Cj4KPkJlY2F1c2UgYSB2YXJpYWJsZSBpcyBub3QgdGhlIHNhbWUgdGhpbmcgYXMgYSBzeW1ib2wuCj4KPkZvciBkeW5hbWljIGJpbmRpbmcsIHlvdSBjYW4gc29tZXcBMAEBAQE- X-Mailer: YahooMailClassic/15.1.8 YahooMailWebService/0.8.144.546 X-detected-operating-system: by eggs.gnu.org: FreeBSD 8.x X-Received-From: 98.139.212.254 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:91333 Archived-At: Stefan Monnier wrote: >> Section 11.9.3 (Lexical Binding) in the manual says "functions like >> `symbol-value', `boundp', and `set' only retrieve or modify >> a variable's dynamic binding". Why? > >Because a variable is not the same thing as a symbol. > >For dynamic binding, you can somewhat blur the difference and use the >symbol's value cell as "the content of the variable of that name" >because let-binding just temporarily changes the only global value. > >With lexical scoping, a given variable name can have many different >values at the same time so this is not an option. I read the last bit as, "with lexical scoping, a given symbol (symbolic name) can be interpreted as many different variables in different scopes (and each variable can have multiple instances) ...", to synchronize terminology. And I call the things that variables are bound to "instances", not "bindings" like the docs do. In the scope of (let ((x 'a)) ...) with lexical binding enabled, since the symbol x is interpreted as a lexical variable rather than as the global variable (the latter bound to the global instance, the value cell for the symbol x), I propose a quote-lex special form, where (quote-lex x), with e.g. "&x" or maybe "^x" as readable syntax, returns a reference to the current instance (current in time and recursion level) of the lexical variable, like "&x" does in C, instead of returning the symbol x (which, without context, is a reference to the global instance). Also change the set function to accept not only symbols, but also lexical instance references, and change symbol-value to either return the value of a symbol's value cell as usual if given the symbol, or return the value of a lexical i nstance if given a reference to the latter. Then you could use argument-mutating functions, including the standard add-to-list function, without having to convert them into macros, and do e.g.: (let ((x '(a))) (add-to-list &x 'b) x) -> (b a) The pair of closures produced by wrap-lexical in my previous message (but the first closure should more simply be just the plain value; oops) imitates what I propose; a special form would be needed to actually return a reference to the lexical instance itself. My set-passed-lexical and get-passed-lexical imitate what I propose for set and symbol-value. Furthermore, instead of having a separate quote-lex, maybe overload quote, and return the symbol as usual where it's used as the global variable, or return a reference to the current lexical instance where the symbol is used as a lexical variable. Then even current code that uses argument-mutating functions could be used unmodified, instead of having to convert their relevant uses of quote to quote-lex. And lexical binding won't cause the accidents I described in my previous message. If overloading quote is a bad idea, then quote-lex should return a reference to the current instance of the given variable regardless of whether it's given a lexical or global variable; that means in the latter case, it does the same thing as quote, which means quote-lex can be used instead of quote in all places, except where a symbol needs to be returned despite that symbol also serving as a lexical variable in the same scope, because the symbol will be used as the global variable or as something other than a variable. >> (let ((x '(a))) (add-to-list 'x 'b) x) -> (b a) > >Yup, this is asking for trouble. Use `push' or `cl-pushnew' instead. So, converting every argument-mutating function into a macro actually _is_ the right thing to do? That seems unnecessarily complicated, just a way of working around the lack of lexical quoting.