[plt-scheme] stupid Swindle tricks
Eli Barzilay writes:
> On May 26, Doug Orleans wrote:
> > Candidates for swindle/misc.ss, in decreasing order of usefulness:
> >
> > (defsyntax* set-if!
> > (syntax-rules ()
> > ((_ condition then-place else-place val)
> > (if condition (set! then-place val) (set! else-place val)))))
>
> I thought about adding that at the time, but there was some reason not
> to do it. Possibly the double code output in `val'.
Unfortunately, (set! (cond ...) val) doesn't seem to work, even if you
define set-begin! and set-#%top!. Probably because the macros come
from a different place. Anyway, this isn't earth-shatteringly useful,
but I thought it was a cute hack.
> > (defsyntax* last-of
> > (syntax-rules ()
> > ((_ successor first clause ...)
> > (collect (x first (successor x)) clause ...))))
I think this is useful. Maybe it needs a better name. I think it's a
good abstraction of "apply a function repeatedly and return the
last result" (where "last" is defined by the conditions in the other
clauses). The rest of the stuff I posted is mostly just one
particular use for this, but those are probably too contrived. (It
was late at night, I was a little loopy...)
--dougorleans at gmail.com