Re: using hidden parameters?

2014-06-14 Thread Linus Ericsson
A more commonly used feature are bindings, which are sort of pluggable (or rather overridable) dynamic vars. http://stackoverflow.com/questions/1523240/let-vs-binding-in-clojure In short you declare a variable as dynamic and then use some binding around the function-call. Sort of a reusable

using hidden parameters?

2014-06-13 Thread Christopher Howard
This might be kind of perverse, but I was wondering if it was possible to write a function or macro that takes hidden parameters, i.e., uses symbols defined in the scope of use, without passing them in explicitly. For example, function next-number takes hidden parameter x, so = (let [x 12]

Re: using hidden parameters?

2014-06-13 Thread James Reeves
It is possible with macros: (defmacro next-number [] '(+ x 1)) Note that I'm using ' and not ` here, so the x isn't resolved. If I wanted to use backticks, I'd need to write: (defmacro next-number [] `(+ ~'x 1)) Macros also get an implicit env binding that gives them access to the local

Re: using hidden parameters?

2014-06-13 Thread Mars0i
Here's a way to do it. Not sure if this is what you want. (let [x (atom 12)] (defn next-number [] (swap! x inc))) Functions are clojures, which means that next-number can retain a pointer to a variable that it can see when it's defined. If some of the ideas here are unfamiliar: The atom