Getting back to the initial post, this would be the (almost)
equivalent code in java:
public class Test{
static int x = 1;
void bindingX(int val){
x = val;
}
int dummyFn2(){
return x + 1;
}
void dummyFn(){
System.out.println("entering function: " + x);
int x = 100;
System.out.println("after let: " + x);
x = dummyFn2();
System.out.println("after let and dummy2: " + x);
bindingX(100);
System.out.println("after binding: " + x);
x = dummyFn2();
System.out.println("after binding and dummy2: " + x);
}
public static void main(String[] args){
new Test().dummyFn();
}
}
The confusion lies in poor naming style, conflating local names with
global names, and not writing functions in a functional style.
On Nov 20, 7:40 pm, kunjaan <[email protected]> wrote:
> Even though I have used Clojure, I hadn't looked at the scoping rules
> in detail. I am getting more confused as I read the documentations. I
> made a small test to try out the scoping resolutions and am apalled at
> the complexity. Could somebody explain the intent and various rules
> that Clojure uses?
>
> (def x 1)
>
> (defn dummy-fn2[]
> (+ x 1))
>
> (defn dummy-fn[]
> (println "entering function: " x)
> (let [x 100]
> (println "after let: " x)
> (let [x (dummy-fn2)]
> (println "after let and dummy2: " x)
> (binding [x 100]
> (println "after binding: " x)
> (let [x (dummy-fn2)]
> (println "after binding and dummy2: " x))))))
>
> 1:2 foo=> (dummy-fn)
> entering function: 1
> after let: 100
> after let and dummy2: 2
> after binding: 2
> after binding and dummy2: 101
> nil
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en