My point was that it is not a missing capability,

Say you want to accumulate some changes, in this case sum odd numbers:
In C++ someone might write this:
int x = 0;
for (int i=0; i<100; i++) {
   if ( i%2==1 ) x+=i;
}

However in Clojure you have a choice:
(reduce + (range 1 100 2))

Or you could do a direct translation to Clojure:
(with-local-vars [i 0, x 0]
  (while (< @i 100)
    (if (= 1 (rem @i 2)) (var-set x (+ @x @i)))
    (var-set i (inc @i)))
  @x)

Both get the same result, but have very different styles.
The version without variables is much easier to understand, provided
you know what reduce does. So it takes a little bit of work initially
to stop using variables, but it is well worth the effort.


Regards,
Tim.
--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to