by Joost Diepenmaat <joost@[EMAIL PROTECTED]
>
Jul 25, 2008 at 07:35 PM
Ari Krupnik <ari@[EMAIL PROTECTED]
> writes:
> This is not a question about preventing accidental multiple evaluation
> in macros, but rather about forcing multiple evaluation in functions.
>
> Let's say I want to create a list of 5 random numbers like this:
>
> (make-list 5 :initial-element (random 1.0))
>
> This gives me a list of 5 identical numbers, because (random 1.0) is
> only evaluated once before being passed to make-list. Is there away
> around this?
A single argument passed to a single function call will always be
evaluated only once.
The problem isn't exactly that (random 1.0) is only evaluated once
(all function call arguments are), it's that make-list is explictly
designed to set every element to the same value.
If you want different behaviour, you'd have to create your own
implementation of make-list, possibly as a macro, or as a function
that takes a "generator" function as an argument. Or use
(list (random 1.0) (random 1.0) (random 1.0) (random 1.0) (random
1.0))
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/
| work: http://zeekat.nl/