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 2 of 21 Topic 13146 of 13806
Post > Topic >>

Re: Multiple evaluation

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/
 




 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 Sat Nov 22 8:02:16 CST 2008.