The following idea came to me in the shower, sort of out of the blue, and I
don't know why I didn't think of it before(I'm disappointed with myself)
so, why not use the same thing as clojure does? even though it does it in
java, you can do it in clojure, the only thing is that you have to do it
once, probably where you define the var, such as(well unfortunately it
doesn't work O_o maybe someone can explain?):
(I was gonna try java interop but I notice there's *
clojure.core/push-thread-bindings*)

=>* (def ^:dynamic *test4* false)*
#'cgws.notcore/*test4*
=> *(push-thread-bindings {#'*test4* true})*
nil
=> **test4**
*false*
=> (pop-thread-bindings)
nil
=> *test4*
false

=> (def ^:dynamic a 1)
#'cgws.notcore/a
=> (push-thread-bindings {#'a 2})
nil
=> a
1
=> (set! a 3)
IllegalStateException Can't change/establish root binding of: a with set
clojure.lang.Var.set (Var.java:233)

(defn *push-thread-bindings*
  "WARNING: This is a low-level function. Prefer high-level macros like
  binding where ever possible.

  Takes a map of Var/value pairs. Binds each Var to the associated value for
  the current thread. Each call *MUST* be accompanied by a matching call to
  pop-thread-bindings wrapped in a try-finally!

      (push-thread-bindings bindings)
      (try
        ...
        (finally
          (pop-thread-bindings)))"
  {:added "1.1"
   :static true}
  [bindings]
  (clojure.lang.Var/pushThreadBindings bindings))
nil

=>* *clojure-version**
{:interim true, :major 1, :minor* 6*, :incremental 0, :qualifier "master"}


so if this worked as I expected then the following two statements would be
in the same place:
=> (def ^:dynamic *test1*)
#'cgws.notcore/*test1*
=> (push-thread-bindings {#'test1 "default value here"})
nil

;and the third could be anywhere (in current thread, 'cause just as
clojure's *warn-on-reflection* when on a different thread you still can't
set! it)
=> (set! test1 "user value")
IllegalStateException Can't change/establish root binding of: test1 with
set  clojure.lang.Var.set (Var.java:233)

*So, is **push-thread-bindings broken(unlikely) or am I missing
something(most certainly so) ?*



On Fri, May 17, 2013 at 6:49 PM, Phillip Lord
<phillip.l...@newcastle.ac.uk>wrote:

> Jim <jimpil1...@gmail.com> writes:
>
> > 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... :)
>
>
> Well, I an proficient in python, so it's probably easier just to use
> python. Even if the documentation sucks.
>
>
> >> Which gives me the dynamic scoped behaviour, but not the global
> >> resetting behaviour.
> > 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...
> :)
>
>
> It's okay! I have a workable solution now, even if it still seems a
> little unfair that I cannot take the same approach that clojure.core
> does under the same circumstances!
>
> Phil
>
> --
> --
> 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.
>
>
>

-- 
-- 
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.


Reply via email to