by pjb@[EMAIL PROTECTED]
(Pascal J. Bourguignon)
Jul 25, 2008 at 07:47 PM
Zach Beane <xach@[EMAIL PROTECTED]
> writes:
> 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?
>
> I don't really think that's behavior to work "around", since it's
> working as it should. There are other ways to achieve what you want,
> though. For example:
>
> (mapcar #'random (make-list 5 :initial-element 1.0))
Consing O(2N)...
(map-into (make-list 5) (lambda () (random 1.0))) ; consing O(N).
--
__Pascal Bourguignon__ http://www.informatimago.com/
CONSUMER NOTICE: Because of the "uncertainty principle," it is
impossible for the consumer to simultaneously know both the precise
location and velocity of this product.