Message from discussion
macro to add let-statements automatically
Received: by 10.66.73.1 with SMTP id h1mr7569191pav.0.1352737139603;
Mon, 12 Nov 2012 08:18:59 -0800 (PST)
Path: s9ni6439pbb.0!nntp.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!spln!extra.newsguy.com!newsp.newsguy.com!enews2
From: "WJ" <w_a_x_...@yahoo.com>
Newsgroups: comp.lang.lisp
Subject: Re: macro to add let-statements automatically
Date: 12 Nov 2012 16:18:16 GMT
Organization: NewsGuy - Unlimited Usenet $19.95
Lines: 28
Message-ID: <k7r7g80lht@enews2.newsguy.com>
References: <2059c391-f401-4a36-a1cc-bbe77209cbc1@googlegroups.com>
NNTP-Posting-Host: pd280285ec5459997e5ec956b0ee42fe3abb3567353df3e3194249b2f72d3dd15.newsdawg.com
Mime-Version: 1.0
User-Agent: XanaNews/1.18.1.6
X-Antivirus: avast! (VPS 121111-1, 11/11/2012), Outbound message
X-Antivirus-Status: Clean
X-Received-Bytes: 1682
Content-Type: text/plain; charset=iso-8859-1
Florian Dietz wrote:
> I am trying to write a rather complicated macro and would like to know how to do this efficiently. The problem is that each use of the macro alters the whole function it is contained in:
>
> the macro should have this form when used: (<macro> <symbol> <value>)
> It should act just like setq, but for each use of the macro in a function (that is, anywhere in the function), the function should get a let statement to make the symbol locally scoped (initialized to nil). This would make it possible to ignore writing let statements. an example:
>
> (lambda ()
> (if a (<macro> a 1) (<macro> a 2))
> (<macro> b (* a 2))
> b)
>
> should become:
>
> (lambda () (let ((a nil) (b nil))
> (if a (setq a 1) (setq a 2))
> (setq b (* a 2))
> b))
>
> How can I do this?
Do you really need this? What's wrong with simply typing
(lambda ()
(let (a b))
(if a (setq a 1) (setq a 2))
(setq b (* a 2))
b))