> Most structures of this type would start life as a uniquely-referenced > structure (either empty or a copy of an immutable), and have > lots of mutations effectively applied to them in a safe environment, > until they are ready to be "frozen" and released to the world as > an immutable version of the structure.
It is possible to achieve this behavior explicitly if you really wanted to: (defn create-add-2 [] (with-local-vars [x 1] (do (var-set x 1) (var-set x (inc @x)) (let [z @x] (fn [y] (+ y z)))))) > (Some structures would > stay uniquely-referenced their whole life - used for performance > in some single-threaded encapsulated mutation-based algorithm.) Such an aggressive optimizer might be unhappy with a runtime check and opt for an unsafe mutable: user=> (def p (java.awt.Point. 0 0)) #'user/p user=> p #<Point java.awt.Point[x=0,y=0]> user=> (.setLocation p 1 2) nil user=> p #<Point java.awt.Point[x=1,y=2]> But might still be unhappy with having to use object calls, at which point I don't think Clojure is the right language. However lucky for them they could still go away and implement an incredibly efficient java api and call it from within Clojure very easily. They would still want to wring the last few drops of performance and write it in C. Actually they could still invoke that code at a high level via JNI but of course would want to keep the calls to a minimum to avoid calling overhead. > I should also clarify one point. I am not "asking for this language > feature" so much as "asking whether people have thought > about it". There may (or may not) be good reasons for not offering > such a language feature. I'm just wondering if it has been > considered. (And trying to get a feel for the strengths and > weaknesses of Clojure - I am very new to it.) I'm just an observer, but if I can't see such a feature appealing to "the performance user" because it wont ever be as fast as they want it to be. To appeal to the general user transparent implementation, which it can't be if you want to preserve all the features. A subset between these exist, but is quite small and not a far step from moving up or down. > * uniquely-referenced (arbitrary mutation changes effectively > allowed, but only ever referred to uniquely (runtime enforced)). I think that pretty accurately describes C++, its not fun debugging a runtime enforced coredump full of crap. :) I know that's not what your proposing sorry but I couldn't resist the analogy! I'm not saying its a bad idea, I just don't find it compelling to me personally. 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 -~----------~----~----~----~------~----~------~--~---