From: Alan Mackenzie <acm@muc.de>
To: Philipp Stephani <p.stephani2@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Trouble with lexical-binding.
Date: Tue, 14 Apr 2015 14:03:13 +0000 [thread overview]
Message-ID: <20150414140313.GA4612@acm.fritz.box> (raw)
In-Reply-To: <CAArVCkR1ZxSLdER_7b5fFvAKv8sffcAb53BsJ-=v0ULmcOx2Og@mail.gmail.com>
Hello, Philipp
On Mon, Apr 13, 2015 at 10:19:14PM +0000, Philipp Stephani wrote:
> IIUC only the local variable is relevant. At least that's the case for
> loading, and it would make sense for byte compilation as well. Byte
> compilation transforms the lexical binding into a stack access and gets rid
> of the 'ptr' symbol entirely.
> > What do I have to do to get `ptr' in this context a special variable
> > (whilst still having it lexically bound in other code)?
> The correct way is to avoid eval and use a closure instead:
> (let* ((ptr (copy-tree ,x))
> (form (lambda () (setcar ptr 'a)))
> (result (funcall form)))
> (message "result is %s, ptr is %s" result ptr))
Thanks, this (almost) works. In the end, in my actual code, I needed to
put a backquote on (lambda ...), so as to be able to evaluate something
inside it with a comma. There's always a way.
> Not only will this work with lexical binding, the byte compiler is able to
> provide better error messages (e.g. if you try to call an undefined
> function in the form) and enable additional optimizations.
Yes. And it even works without lexical binding, which is a bonus.
--
Alan Mackenzie (Nuremberg, Germany).
next prev parent reply other threads:[~2015-04-14 14:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-13 22:03 Trouble with lexical-binding Alan Mackenzie
2015-04-13 22:19 ` Philipp Stephani
2015-04-14 14:03 ` Alan Mackenzie [this message]
2015-04-14 16:53 ` Stefan Monnier
2015-04-15 13:44 ` Alan Mackenzie
2015-04-15 14:34 ` Stefan Monnier
2015-04-13 22:28 ` Stefan Monnier
2015-04-15 13:48 ` Nicolas Richard
2015-04-15 14:44 ` Stefan Monnier
2015-04-16 17:34 ` Nicolas Richard
2015-04-16 18:43 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150414140313.GA4612@acm.fritz.box \
--to=acm@muc.de \
--cc=emacs-devel@gnu.org \
--cc=p.stephani2@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.