Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #148: Insert coin for new game


comp / comp.lang.lisp / Re: simple loop question

SubjectAuthor
o Re: simple loop questionB. Pym

1
Subject: Re: simple loop question
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Sun, 22 Sep 2024 06:45 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: simple loop question
Date: Sun, 22 Sep 2024 06:45:50 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <vcoeet$249pf$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sun, 22 Sep 2024 08:45:50 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="67a8704918c17bf3123f7c46350c79f3";
logging-data="2238255"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19MUDijtsaErIN0CpF5wPVo"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:Tb0cYXOBlSTh6VMeC9Mbb6zAaJA=
View all headers

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.

1

rocksolid light 0.9.8
clearnet tor