www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Article on Clojure

(I have being quite busy for some days, I have many posts to catch up.)

A nice article aboue Clojure for Java programmers:
"Clojure: Challenge your Java assumptions", by Joshua Fox:

http://tinyurl.com/pxpwdh

Original URL:
http://www.javaworld.com/cgi-bin/mailto/x_java.cgi?pagetosend=/export/home/httpd/javaworld/javaworld/jw-05-2009/jw-05-clojure.html

Some quotations from the article:

The original map [associative array] remains unchanged. This would seem to make
for inefficient copying every time a change is needed, but in fact it enables a
nice optimization: immutable objects, like the two maps above, can share parts
of their underlying structure, with no risk of changes to one structure
affecting the other one inadvertently.<
By default, Clojure functions are pure functions: [...] Pure functions are also
easy for Clojure itself to understand, and so to apply optimizations. Pure
function calls can run in parallel, without regard for order; they can run in
separate cores without the risk of interfering with one another's results. They
can be rerun safely when a transaction fails, and their execution can be
deferred until the results are needed. Their results can be memoized -- cached
for lookup on subsequent invocations.<
A Clojure Var provides a way to rebind a variable temporarily within a thread.
It passes information long-distance like a global variable. It does this
safely, because the value is only visible in a single thread, and only in the
dynamic scope of the binding's runtime invocation. A Java thread-local variable
is similar: It passes state "long distance," skipping levels of the call stack,
while avoiding the cross-thread risks of static fields. However, it continues
to live throughout the thread and is not restricted to a well-defined dynamic
scope, as a Var binding is.<
I think lot of my functions in D2 code will be pure. At the moment D2 has no immutable data structures yet in its std lib (like the associative arrays in Clojure, etc). Bye, bearophile
May 12 2009