emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

macros and the lexical environment


From: Nic Ferrier
Subject: macros and the lexical environment
Date: Tue, 04 Jun 2013 22:48:06 +0100

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 via email to

[Prev in Thread] Current Thread [Next in Thread]