Hi,
If I have something like
(defun blah (x y z)
(let ((a 1) (b 2) (c 3))
(print (local-vars))
(print (+ a x))
(print (+ b y))
(print (+ c z))))
How would I write (local-vars) ?
It would return (a b c), a list of the local vars.
Would it be possible to write it without writing a some kind of
replacement for let ?
Any ideas, criticisms welcome.
Regards
PS Code above is 'lisp pseudo-code', freehand typed, not sure it
parses correctly.
David
On Jun 23, 6:14 am, dc <··············@gmail.com> wrote:
> Hi,
>
> If I have something like
>
> (defun blah (x y z)
> (let ((a 1) (b 2) (c 3))
> (print (local-vars))
> (print (+ a x))
> (print (+ b y))
> (print (+ c z))))
>
> How would I write (local-vars) ?
> It would return (a b c), a list of the local vars.
>
> Would it be possible to write it without writing a some kind of
> replacement for let ?
>
> Any ideas, criticisms welcome.
>
> Regards
>
> PS Code above is 'lisp pseudo-code', freehand typed, not sure it
> parses correctly.
> David
This is probably not a very good idea, but:
CL-USER> (macrolet ((local-vars ()
(let ((lex sb-c:*lexenv*))
`'(,@(loop :for var :in (reverse (sb-c::lexenv-
vars lex))
:collect (car var))))))
(flet ((blah (x y z)
(let ((a 1) (b 2) (c 3))
(print (local-vars))
(print (+ a x))
(print (+ b y))
(print (+ c z)))))
(blah 4 5 6)))
(X Y Z A B C)
5
7
9
CL-USER> (lisp-implementation-type)
"SBCL"
CL-USER> (lisp-implementation-version)
"1.0.29.19"
USENET sucks by the way. There is not a _single_ decent GUI or Web
client out there.
From: http://public.xdi.org/=pf
Subject: Re: Is it possible to get a list of local variables inside a defun?
Date:
Message-ID: <m2hby7fjaa.fsf@wyoming.home>
Lars Rune N�stdal <···········@gmail.com> writes:
> USENET sucks by the way. There is not a _single_ decent GUI or Web
> client out there.
Usenet sucks? Perhaps, but it's infinitely preferable to the common
alternatives (web forums...like sticking needles in your eyes)
What's wrong with Gnus?
On Jun 23, 10:26 am, Paul Foley <····@below.invalid> (http://
public.xdi.org/=pf) wrote:
> Lars Rune Nøstdal <···········@gmail.com> writes:
>
> > USENET sucks by the way. There is not a _single_ decent GUI or Web
> > client out there.
>
> Usenet sucks? Perhaps, but it's infinitely preferable to the common
> alternatives (web forums...like sticking needles in your eyes)
>
> What's wrong with Gnus?
It comes with a manual.
From: Kaz Kylheku
Subject: Re: Is it possible to get a list of local variables inside a defun?
Date:
Message-ID: <20090705230248.786@gmail.com>
On 2009-06-23, Lars Rune Nøstdal <···········@gmail.com> wrote:
> USENET sucks by the way. There is not a _single_ decent GUI or Web
> client out there.
And so your reaction is to use the worst? :)
From: David Golden
Subject: Re: Is it possible to get a list of local variables inside a defun?
Date:
Message-ID: <h1rs26$80d$1@aioe.org>
Lars Rune N�stdal wrote:
> USENET sucks by the way. There is not a _single_ decent GUI or Web
> client out there.
Shrug. Mozilla Thunderbird does nntp and AFAIK works on all major
platforms if you want click'n'drool.
> Hi,
>
> If I have something like
>
> (defun blah (x y z)
> (let ((a 1) (b 2) (c 3))
> (print (local-vars))
> (print (+ a x))
> (print (+ b y))
> (print (+ c z))))
>
> How would I write (local-vars) ?
> It would return (a b c), a list of the local vars.
>
> Would it be possible to write it without writing a some kind of
> replacement for let ?
It looks like you need codewalker, redefine not let, but a defun
itself.
Or maybe define your own "hairy-defun". Good examples of codewalkers
are
iterate, ap5 and screamer.