From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nic Ferrier Newsgroups: gmane.emacs.devel Subject: macros and the lexical environment Date: Tue, 04 Jun 2013 22:48:06 +0100 Message-ID: <87ip1tim3t.fsf@ferrier.me.uk> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1370382506 30936 80.91.229.3 (4 Jun 2013 21:48:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 4 Jun 2013 21:48:26 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jun 04 23:48:23 2013 Return-path: Envelope-to: ged-emacs-devel@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 1Ujz5Y-0006V2-O7 for ged-emacs-devel@m.gmane.org; Tue, 04 Jun 2013 23:48:20 +0200 Original-Received: from localhost ([::1]:37917 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ujz5X-00018p-QS for ged-emacs-devel@m.gmane.org; Tue, 04 Jun 2013 17:48:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41823) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ujz5S-00018k-Sj for emacs-devel@gnu.org; Tue, 04 Jun 2013 17:48:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ujz5Q-0007sh-Ja for emacs-devel@gnu.org; Tue, 04 Jun 2013 17:48:14 -0400 Original-Received: from static.17.66.46.78.clients.your-server.de ([78.46.66.17]:46447 helo=po1.ferrier.me.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ujz5Q-0007pj-Ct for emacs-devel@gnu.org; Tue, 04 Jun 2013 17:48:12 -0400 Original-Received: from nferrier (140.35.155.90.in-addr.arpa [90.155.35.140]) by po1.ferrier.me.uk (Postfix) with ESMTP id A11C1AC0063; Tue, 4 Jun 2013 23:48:11 +0200 (CEST) Original-Received: from nferrier (localhost [127.0.0.1]) by nferrier (Postfix) with ESMTPS id 92BA01600B7; Tue, 4 Jun 2013 22:48:06 +0100 (BST) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 78.46.66.17 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:160086 Archived-At: 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?