From: Krzysztof Drewniak on 5 May 2010 19:04 On 2010-05-05, Captain Obvious <udodenko(a)users.sourceforge.net> wrote: > KD> While sitting in class bored (I know, great passtime) I had an > KD> idea. Functions would work great especially if there was a dynamic-let > KD> (or something) which would work just like let but create variables > KD> that are dynamic, not lexical. For example: > KD> (defun foo () > KD> (dynamic-let ((x 3)) > KD> (funcall #'(lambda () (print x))))) > KD> and (foo) would print 3. However, I have no idea how to *write* such a > KD> macro. Dang. Any help? > > It is simple: > > (let ((x 3)) > (declare (special x)) > ...) > > will create a dynamic variable binding. > > However, to be fully standard-compatible, you need to declare them special > in your function too. > > E.g. > > CL-USER> (defvar *foo* (lambda () > (locally (declare (special x y)) > (+ x y)))) > *FOO* > CL-USER> (let ((x 3) (y 5)) (declare (special x y)) (funcall *foo*)) > 8 > > But it works even if you do not declare them special in most > implementations, might produce warnings, though. > This will work. I guess I'll just have to put up with it. Thank you for all the help ovwer these last few days. *gets back to coding work* Krzysztof Drewniak -- X-Real-Email-With-Antispam: krzysdrewniak at gmail dot com pgp key on keyserver.ubuntu.com and maybe some other place too
|
Pages: 1 Prev: PROJECT TRACKING SOFTWARE Next: dylan tech release package |