Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Lisp > Re: Multiple ev...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 21 Topic 13146 of 13602
Post > Topic >>

Re: Multiple evaluation

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.
 




 21 Posts in Topic:
Multiple evaluation
Ari Krupnik <ari@[EMAI  2008-07-25 10:28:02 
Re: Multiple evaluation
Joost Diepenmaat <joos  2008-07-25 19:35:07 
Re: Multiple evaluation
pjb@[EMAIL PROTECTED] (P  2008-07-25 19:43:21 
Re: Multiple evaluation
Zach Beane <xach@[EMAI  2008-07-25 13:37:31 
Re: Multiple evaluation
pjb@[EMAIL PROTECTED] (P  2008-07-25 19:47:30 
Re: Multiple evaluation
Daniel Janus <przesunm  2008-07-25 18:42:02 
Re: Multiple evaluation
Ari Krupnik <ari@[EMAI  2008-07-25 11:40:07 
Re: Multiple evaluation
rpw3@[EMAIL PROTECTED] (  2008-07-25 21:46:40 
Re: Multiple evaluation
pjb@[EMAIL PROTECTED] (P  2008-07-26 08:08:09 
Re: Multiple evaluation
rpw3@[EMAIL PROTECTED] (  2008-07-26 09:16:31 
Re: Multiple evaluation
"John Thingstad"  2008-07-25 21:37:31 
Re: Multiple evaluation
Sacha <none@[EMAIL PRO  2008-07-25 23:37:17 
Re: Multiple evaluation
tar@[EMAIL PROTECTED] (T  2008-07-25 17:32:13 
Re: Multiple evaluation
Sacha <none@[EMAIL PRO  2008-07-26 04:00:32 
Re: Multiple evaluation
Stephen Compall <s11@[  2008-07-25 20:18:55 
Re: Multiple evaluation
Ari Krupnik <ari@[EMAI  2008-07-25 22:42:16 
Re: Multiple evaluation
pjb@[EMAIL PROTECTED] (P  2008-07-26 08:07:00 
Re: Multiple evaluation
"Dimiter \"malk  2008-07-28 12:41:13 
Re: Multiple evaluation
Rainer Joswig <joswig@  2008-07-28 23:49:54 
Re: Multiple evaluation
Ari Krupnik <ari@[EMAI  2008-07-28 12:42:48 
Re: Multiple evaluation
Kent M Pitman <pitman@  2008-07-28 19:06:12 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Oct 10 19:55:57 CDT 2008.