Re: A problem about position of function used by binding

2017-02-07 Thread guid

 @Matching Socks, thank you very much.

-- 
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/d/optout.


Re: A problem about position of function used by binding

2017-02-07 Thread Matching Socks

There is a manual! https://clojure.org/reference/documentation - see 
especially under Vars and Compilation.

-- 
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/d/optout.


Re: A problem about position of function used by binding

2017-02-06 Thread guid
James, thank you very much 

Yes, I can fix it by using ^:dynamic or using #'test1 in test4, but I want 
to know what happened when I call test4.

>so it'll optimise out the var for performance.
if you mean it will not check bounding list when I call test1 within test4

Does any document or book can help me to understand it ?

-- 
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/d/optout.


Re: A problem about position of function used by binding

2017-02-06 Thread James Reeves
When you define test4 in your first example, the compiler doesn't know that
test1 is dynamic, so it'll optimise out the var for performance.

To fix it, ensure that the var is declared as dynamic:

  (declare ^:dynamic test1)

- James

On 7 February 2017 at 03:26, guid  wrote:

> hello everyone
>
> I have a problem about binding function in clojure1.8.
> when I changed position of function which call a bound function I got
> different result.
>
> If I define test4 (call test1 within it) before test1, binding would not
> work
>
> (declare test1)
>
> (defn test2 [](prn "test2"))
>
>
> (defn test4 [] (test1))
>
>
> (defn ^:dynamic test1 [] (prn "dynamic test1"))
>
>
> (defn testB []
>   (binding [test1 test2]
> (test1)
> (test4)
> ))
>
>
> when I call (testB) result is
>
> "test2"
> "dynamic test1"
>
>
> But if I change postion of (defn test4 xxx) and (defn ^:dynamic test1 ), 
> binding will work well.
>
>
> (declare test1)
>
> (defn test2 [](prn "test2"))
>
>
> (defn ^:dynamic test1 [] (prn "dynamic test1"))
>
>
> (defn test4 [] (test1))
>
>
> (defn testB []
>
>   (binding [test1 test2]
> (test1)
> (test4)
> ))
>
>
> result is
>
> "test2"
> "test2"
>
>
> Any way, with-bindings is the same as binding, but why ?
>
>
> 
>
> any help would be appreciated
>
> --
> 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/d/optout.
>

-- 
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/d/optout.