all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Nic Ferrier <nferrier@ferrier.me.uk>
To: emacs-devel@gnu.org
Subject: macros and the lexical environment
Date: Tue, 04 Jun 2013 22:48:06 +0100	[thread overview]
Message-ID: <87ip1tim3t.fsf@ferrier.me.uk> (raw)

A while ago I wrote to the list about s-lex-format, a contribution I
made to magnars excellent s library for string handling.

s-lex-format is designed to let you interpolate values from the current
lexical environment into a string, like this:

  (let ((v 42)
        (a "hello world"))
     (s-lex-format "${a} - the answer is ${v}"))

this is terrifically useful.

However. It's implementation is a pain. I went backwards and forwards
with a dynamic version that looked up the specified values by name,
either by using symbol-value or peeking inside lexical binding (capture
a lambda, look in the closure's list of bindings).

I decided that it would be better to expand the format string into a
list of variable references. But that doesn't work well unless the
string is static, using a reference for the format string doesn't work
because it's not available at compile time:

  (let ((v 42)
        (a "hello world")
        (template "${a} - the answer is ${v}"))
     (s-lex-format template))

will fail to expand.

I'm going to have to go back to getting the dynamic version working for
now.

But what I'm really asking is, isn't this quite a useful thing to want
to do? get at the current environment state? the interpreter must know
the environment state. Could it be exposed to macros at compile time?
Perhaps through some function that returns an alist? or a function with
a symbol-name like interface?

Thoughts?



             reply	other threads:[~2013-06-04 21:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-04 21:48 Nic Ferrier [this message]
2013-06-04 23:07 ` macros and the lexical environment Pascal J. Bourguignon
2013-06-05  8:23   ` Nic Ferrier
2013-06-05  8:35     ` Jambunathan K
2013-06-05 21:08     ` Pascal J. Bourguignon
2013-06-05  1:48 ` Stefan Monnier
2013-06-05 20:34 ` Dmitry Gutov
2013-06-05 22:41   ` Stefan Monnier
2013-06-05 23:46     ` Dmitry Gutov

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=87ip1tim3t.fsf@ferrier.me.uk \
    --to=nferrier@ferrier.me.uk \
    --cc=emacs-devel@gnu.org \
    /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.