On 17/05/13 11:00, Phillip Lord wrote:
It's a nice language, I think. It inherits however the some of the
nastiness of Java, in particular it doesn't integrate at all into the
OS; the makes it not a good fit for little scripting, one-off jobs which
form the basis of a lot of scientific computing.
aaa yes indeed...the jvm is indeed very heavy-weight for such scripting
tasks...on the other hand have you looked at clojure-py? I'm not
up-to-date with its current state/features but it should be viable for
little scripting jobs... :)
Which gives me the dynamic scoped behaviour, but not the global
resetting behaviour.
well, the thing is that Clojure in general is not well suited for
imperative style code. There are some constructs that make it easier
(e.g. with-local-vars), but for the most part you are expected to follow
the 'functional-transformation' route instead of the
'imperative-mutation' one...If you absolutely need the global resettable
behaviour I can only suggest an atom. Then, when you want to use that in
tests, a little try-finally macro which swaps the atom and resets it in
the finally clause would simulate your dynamic scope. I quickly wrote
the following but I get an exception which I don't have the time to sort
at the moment...maybe later this evening... :)
(defmacro abinding [bs & body]
(let [pairs (partition 2 bs) ;;partition the bindings
old-values (map (comp deref first) pairs) ;;save the original
values
_ (doseq [[b v] pairs] (reset! b v)) ;;introduce the new values
restore (fn [] (map #(reset! (first %1) %2) pairs
old-values))] ;;define the restoring fn
`(try
~@body
(finally (restore))) ))
Jim
--
--
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
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.