idempotency

2012-06-30 Thread Brian Marick
In its optimization, does the Clojure compiler ever assume idempotency? That 
is, does it ever look at a function application `(f x y z)` and say to itself 
I may freely substitute the result of the first application of `f` to those 
particular arguments for any later call?

I could imagine it doing that for built-ins (or just primitives?), but not for 
user-defined functions (given the existence of atoms, etc.) I can also imagine 
it not bothering for any calls.

-
Brian Marick, Artisanal Labrador
Contract programming in Ruby and Clojure
Occasional consulting on Agile


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: idempotency

2012-06-30 Thread Softaddicts
You should then use memoize explicitly then. Of course, avoid this if
you have side effects in the function.

Luc


 In its optimization, does the Clojure compiler ever assume idempotency? That 
 is, does it ever look at a function application `(f x y z)` and say to itself 
 I may freely substitute the result of the first application of `f` to those 
 particular arguments for any later call?
 
 I could imagine it doing that for built-ins (or just primitives?), but not 
 for user-defined functions (given the existence of atoms, etc.) I can also 
 imagine it not bothering for any calls.
 
 -
 Brian Marick, Artisanal Labrador
 Contract programming in Ruby and Clojure
 Occasional consulting on Agile
 
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 
--
Softaddictslprefonta...@softaddicts.ca sent by ibisMail from my ipad!

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: idempotency

2012-06-30 Thread Alan Malloy
That's really a stricter requirement than idempotence (ie, functional 
purity). I don't believe the compiler ever does this. The JVM might, if 
it's able to inline some particular method call and discover therein that 
no mutation happens, but that's probably pretty rare given the amount of 
indirection that goes on when calling everything through the IFn interface.

On Saturday, June 30, 2012 5:30:02 PM UTC-7, Brian Marick wrote:

 In its optimization, does the Clojure compiler ever assume idempotency? 
 That is, does it ever look at a function application `(f x y z)` and say to 
 itself I may freely substitute the result of the first application of `f` 
 to those particular arguments for any later call? 

 I could imagine it doing that for built-ins (or just primitives?), but not 
 for user-defined functions (given the existence of atoms, etc.) I can also 
 imagine it not bothering for any calls. 

 - 
 Brian Marick, Artisanal Labrador 
 Contract programming in Ruby and Clojure 
 Occasional consulting on Agile 




-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en