[plt-scheme] stupid Swindle tricks
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'.
> (defsyntax* last-of
> (syntax-rules ()
> ((_ successor first clause ...)
> (collect (x first (successor x)) clause ...))))
>
> (define* (nth-of n successor first)
> (last-of successor first (i <- 0 ..< n)))
>
> (defsyntax* set-nth-of!
> (syntax-rules ()
> ((_ n successor first val)
> (let ((nn n))
> (set! (if (zero? nn)
> first
> (successor (nth-of (1- nn) successor first)))
> val)))))
(These seem too specific.)
> (defsyntax* push-at-end!
> (syntax-rules ()
> ((_ val place)
> (set! (nth-of (length place) cdr place) (list val)))))
>
> (defsyntax* pop-at-end!
> (syntax-rules ()
> ((_ place)
> (begin0 (last place)
> (set! (nth-of (1- (length place)) cdr place) null)))))
Again, they seem too specific, and easy to implement yourself. BTW,
I'd use a simple `append!' for the first, and a simple loop for the
second.
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!