This is the mail archive of the guile@cygnus.com mailing list for the guile project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Marius Vollmer <mvo@zagadka.ping.de> writes:
> Russ McManus <mcmanr@eq.gs.com> writes:
>
> > > Binding temp-var with `let' might be cleaner here.
> >
> > Since I was using 'set!' willy-nilly, I just kept going. See below
> > for version with 'let'.
>
> Yeah, no big deal. The point was not to get rid of one `set!' because
> it isn't functional or something, but to avoid putting so much code
> between the declaration and use of temp-var.
For the hell of it, here's my fluid-let. First of all, from the
wrappers package I posted, I have:
(define-macro (with-wrappers wrapper starter ender symlist form)
(let ((oldsym (map (lambda (sym) (gensym)) symlist)))
`(let ,(map (lambda (old sym)
(list old sym))
oldsym
symlist)
(dynamic-wind (lambda ()
(,starter)
,@(map (lambda (sym)
`(set! ,sym (,wrapper ',sym ,sym)))
symlist))
(lambda ()
,form)
(lambda ()
,@(map (lambda (sym old)
`(set! ,sym ,old))
symlist oldsym)
(,ender))))))
Then, fluid-let is:
(define-macro (fluid-let args . body)
`(with-wrappers (lambda (sym symval) (cadr (assoc sym ',args)))
(lambda () #t)
(lambda () #t)
,(map car args)
(begin ,@body)))
Of course, it'd be better to gut with-wrappers to generate fluid-let:
(define-macro (fluid-let args . body)
(let ((oldsyms (gensym)))
`(let ((,oldsyms ,(map car 'args))
(list old sym))
oldsym
args)
(dynamic-wind (lambda ()
(,starter)
,@(map (lambda (sym)
`(set! ,sym (,wrapper ',sym ,sym)))
symlist))
(lambda ()
,form)
(lambda ()
,@(map (lambda (sym old)
`(set! ,sym ,old))
symlist oldsym)
(,ender))))))
--
Harvey J. Stein
BFM Financial Research
hjstein@bfr.co.il