Am 08.08.2009 um 02:52 schrieb samppi:
> Great, thanks. Is clojure.lang.Var/pushThreadBindings a public,
> supported part of the API? Can I use it without fear of suddenly
> dropped support?
It is was `binding` uses internally. Unfortunately
this is not exported by Clojure's public API. I -
unfortunately - have to rely on this hack.
Sincerely
Meikel
get-/push-/pop-thread-bindings wrapping Var.get/push/popThreadBindings
would be a welcome issue/patch.
Note the addition of getThreadBindings(), which returns a map of all
the current bindings. This could be used to define a
function-returning macro that can be used when you want to pass a
helper function to another thread and have it use the bindings in
effect at the point of its creation.
If someone wants to propose a patch for the latter we can discuss in
clojure-dev.
Rich
Am 08.08.2009 um 15:52 schrieb Rich Hickey:
> get-/push-/pop-thread-bindings wrapping Var.get/push/popThreadBindings
> would be a welcome issue/patch.
>
> Note the addition of getThreadBindings(), which returns a map of all
> the current bindings. This could be used to define a
> function-returning macro that can be used when you want to pass a
> helper function to another thread and have it use the bindings in
> effect at the point of its creation.
>
> If someone wants to propose a patch for the latter we can discuss in
> clojure-dev.
Ok. Will give it a try and post me results on clojure-dev.
Sincerely
Meikel
Am 10.08.2009 um 03:24 schrieb jvt:
> (defmacro with-a-b-c [m & body] `(let [mp# ,mp] a (:a mp#) b (:b mp#)
> c (:c mp#)] ~@body))
>
> Is this a more "idiomatic" solution or a more "lispy" one, or am I
> laboring under a misunderstanding?
I find this not very elegant. Tomorrow you need b, c and d,
so you write another macro. Then you f, g, a and x and write
another macro.... As a minor point: above you probably meant
binding for a, b and c.
Having a solution, which solves this problem once and for all,
is more interesting.
Sincerely
Meikel
I have about six variables that are often rebound together using
binding; these variables are used to access and set data in a state
object (whose type is of the user's choice). These variables' values
(the accessors and setters) are often used together.
I'd like to be able to bundle these values into a map, and using a
function or macro called with-bundle, automatically bind the map's
vals to their respective variables:
(def my-bundle
{'*variable-1* :something1, '*variable-2* :something2})
myString = new JSONObject().put("JSON", "Hello, World!").toString();
// myString is {"JSON": "Hello, World"}
try {
jsonObject = new JSONObject(myString);
}
catch(ParseException pe) {
}
{{script language=groovy}}
def rss = new XmlSlurper().parseText(("http://weather.yahooapis.com/forecastrss?p="
+ xcontext.macro.params.zip).toURL().text)
println rss.channel.title
println "Sunrise: ${rss.channel.astronomy.@sunrise}"
println "Sunset: ${rss.channel.astronomy.@sunset}"
println "Currently:"
println "\t" + rss.channel.item.condition.@date
println "\t" + rss.channel.item.condition.@temp
println "\t" + rss.channel.item.condition.@text
{{/script}}