On Mon, Jan 5, 2009 at 6:35 PM, wubbie <sunj...@gmail.com> wrote:
>
> Hi,
> This example is from clojure site.
> My question is on line 5 and line 6:
> The confusion is str is a function and here looks like used as a
> regular variable.

The var that is clojure.core/str aka. 'str, points to a function that
implements it. And vars, any vars, can be shadowed/rebound
temporarily, and this is what 'binding does.

>
> Thanks in advance.
> Sun
>
>
> (defn loves [x y]
>  (str x " loves " y))
> (defn test-rebind []
>  (println (loves "ricky" "lucy"))
>  (let [str-orig str]    --->  line 5:
>    (binding [str (fn [& args]    --> line 6:
>                    (println "Logging str")
>                    (apply str-orig args))]    -->line 8:
>      (println (loves "fred" "ethel")))))
> (test-rebind)
>
> ricky loves lucy
> Logging str
> Logging str
> Logging str
> Logging str
> Logging str
> fred loves ethel
>
> >
>



-- 
Venlig hilsen / Kind regards,
Christian Vest Hansen.

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

Reply via email to