Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.lisp
Re: simple loop question
William James
9/15/2015 11:21:00 PM
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))
Instead of a macro whose source measures more than
60 kilobytes, we can simply use recursion.
Of course, we can't do that in CL (COBOL-Like), because
any time you use recursion in CL you risk stack-overflow.
Yes, CL is such an ancient, clunky, un-Lispy language
that it doesn't even have TCO.
Gauche Scheme:
(use srfi-27 :only (random-integer))
(let g ((lst ()) (sum 0))
(if (> sum 50)
lst
(let1 x (random-integer 10)
(g (cons x lst) (+ x sum)))))
--
[W]e had enough employees who made more than 85 to fill all the openings. The
highest score that any of the blacks scored on the test was 11. The lowest
score that any black made on the test was 4. All four of those blacks went
into skilled-trades training.
https://archive.org/download/TheOldmanArchives/oldman29-...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: simple loop question
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password