From Newsgroup: comp.lang.scheme
Lars Brinkhoff wrote:
use LOOP to collect random integers into a list until the sum of that
list exceeds a constant (say 50).
(loop for x = (random 10) collect x sum x into y until (> y 50))
Let's see if it's shorter in Gauche Scheme.
(loop (y) (:coll (++. y (random 10))) (:till (> y 50)))
Yes, it is.
Given:
(use srfi-27) ;; random-integer
(define random random-integer)
;; Returns the added number, not the sum.
(define-syntax ++.
(syntax-rules ()
[(++. place val)
(let ((x val)) (set! place (+ x place)) x)]
[(++. place) (++. place 1)]))
I don't want to include the rather lengthy source for
"loop" here, so defining it is left as an exercise for
the reader.
--- Synchronet 3.22a-Linux NewsLink 1.2