unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* macros and the lexical environment
@ 2013-06-04 21:48 Nic Ferrier
  2013-06-04 23:07 ` Pascal J. Bourguignon
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Nic Ferrier @ 2013-06-04 21:48 UTC (permalink / raw)
  To: emacs-devel

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?



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-06-05 23:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-04 21:48 macros and the lexical environment Nic Ferrier
2013-06-04 23:07 ` 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

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).