let binding for functions

2012-12-07 Thread Jingjing
I'm a clojure newbie. Why does the compiler complain about being unable to resolve cube-root-recur on line 17? thanks 1 (def cube-root 2 (fn [n]

Re: let binding ~'=

2010-08-21 Thread Joop Kiefte
it is a macro with a syntax quote, so all symbols are namespace-qualified. so = will actually be clojure.core/= the ~' removes this namespace-qualification, so it is rendered as just =. 2010/8/21 limux liumengji...@gmail.com: This is some code in a blog of William Gropper, the useage of ~'=

Re: let binding ~'=

2010-08-21 Thread Nicolas Oury
Clojure whitin a `(...) context resolves the name space of symbols. This is most often what you want and prevent some name collisions at macro expension. But as binders can not be name-space resolved this do not allow to write: `(let [and ]) this would expand to (let [ns/and ...]) which

Re: let binding ~'=

2010-08-21 Thread limux
Is where a canonical doc about ~' or I have to read the core.clj? On 8月21日, 下午10时40分, Nicolas Oury nicolas.o...@gmail.com wrote: Clojure whitin a `(...) context resolves the name space of symbols. This is most often what you want and prevent some name collisions at macro expension. But as

Re: let binding ~'=

2010-08-21 Thread limux
Thanks, I remindered that it's a reader macro used to get the symbol itself exactly without namespace. Ok, I see! On 8月21日, 下午10时58分, limux liumengji...@gmail.com wrote: Is where a canonical doc about ~' or I have to read the core.clj? On 8月21日, 下午10时40分, Nicolas Oury nicolas.o...@gmail.com

Re: let binding ~'=

2010-08-21 Thread Brian Goslinga
On Aug 21, 9:58 am, limux liumengji...@gmail.com wrote: Is where a canonical doc about ~' or I have to read the core.clj? ~' is not an actual thing. Note that `~expr is the same as expr, so `~'foo is the same as 'foo is the same as (quote foo), which when evaluated yields the symbol foo. --

Re: let binding and recursive function

2010-08-04 Thread Emeka
Hello John, I would want to add something to what Justin said. (defn goo [ i k l] (println l)) = (goo 2 3 [233]) ;;; gives ([233]) (conj '([233]) ...) (defn goo [i k [l]](println l)) =(goo 2 3 [233]) ;;; gives [233] (conj [233] ...) Hope the difference is clear now. Emeka On Mon, Aug 2,

let binding and recursive function

2010-08-02 Thread John Sanda
I've just implemented an inorder traversal function for a vector-based tree. The functions look like, (defn- do-traversal [tree idx traversal] (cond (not (node-exists? tree idx)) traversal (leaf? tree idx) (conj traversal (tree idx)) :else (apply conj (do-traversal tree

Re: let binding and recursive function

2010-08-02 Thread Justin Kramer
I think you want: (defn- do-traversal [tree idx [tree-traversal]] ...) Note the extra brackets for destructuring. Another alternative is using multiple arg lists: (defn- do-traversal ([tree idx] (do-traversal tree idx [])) ([tree idx traversal] ...)) Lastly, FYI, the form (if

Re: let binding and recursive function

2010-08-02 Thread John Sanda
Thanks for the response and suggestions Justin. A co-worker also just suggested multiple arg lists which is perfect. He also suggested (or foo bar) to further simplify my code. It definitely cleans the code up and improves readability. - John On Mon, Aug 2, 2010 at 5:37 PM, Justin Kramer

Re: special forms and let binding

2010-05-31 Thread alux
Hello ataggart, thank you for the correction! Only now I understand A.Rosts question. May be somebody can help, and explain why my hypothesis was wrong. Obviousely, while functions are first class, special forms are even better, kind of zeroth class. Thank you, alux On 31 Mai, 04:15, ataggart

Re: special forms and let binding

2010-05-31 Thread Аркадий Рост
In fact, keywords are not symbols. So thats why you were wrong. You can read about in on the page http://clojure.org/lisps -- 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

Re: special forms and let binding

2010-05-31 Thread Ark. Rost
So I don't understand if there any way do it. I'm really curious about 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

Re: special forms and let binding

2010-05-31 Thread alux
Hi Аркадий, I started another thread about the difference between special form and macros today - and got told that it is not possible to overwrite a special form. Regards, alux On 31 Mai, 21:15, Ark. Rost arkr...@gmail.com wrote: So I don't understand if there any way do it. I'm really

special forms and let binding

2010-05-30 Thread A.Rost
Hi! For example, it's possible to do things like: (def do println) ((var do) example) And it works correct. But I don't understand how to get the same behavior in let bindings. I mean (let [do println] ..) what can I write to get the same results? -- You received this message

Re: special forms and let binding

2010-05-30 Thread alux
Hi A., I dont completely understand what you refer to with works correct. You define a local variable, named do, and use it. That works of course. Btw you may use it without the call to var (def do println) (do example) In let you may do (let [do println] (do :plop)) Is this what you want?

Re: special forms and let binding

2010-05-30 Thread ataggart
On May 30, 12:45 pm, alux alu...@googlemail.com wrote: Hi A., I dont completely understand what you refer to with works correct. You define a local variable, named do, and use it.  That works of course. Btw you may use it without the call to var (def do println) (do example) It only

Re: let-binding overrides binding-binding

2010-02-01 Thread Alex Osborne
Tom Hicks hickstoh...@gmail.com writes: I can't seem to do this with the 'inc' function: user= (binding [inc (fn [y] (+ 2 y))] (inc 44)) 45 Why doesn't this work? See this thread: http://groups.google.com/group/clojure/browse_thread/thread/d772e114e50aace6 -- You received this message

Re: let-binding overrides binding-binding

2009-12-25 Thread Richard Newman
Actually, I think shadowing core functions is not a great idea Quite so! Common Lisp expressly prohibits this stuff for the COMMON- LISP package. but I wanted to understand the principles involved here. Thanks again for your rapid help. My pleasure. Happy Christmas! -- You received this

Re: let-binding overrides binding-binding

2009-12-24 Thread Tom Hicks
On a related note, can someone explain the following... I can define a function 'p1': user= (defn p1 [x] (+ 1 x)) #'user/p1 user= (p1 44) 45 and then shadow it within the binding construct: user= (binding [p1 (fn [y] (+ 2 y))] (p1 44)) 46 but, I can't seem to do this with the 'inc' function:

Re: let-binding overrides binding-binding

2009-12-24 Thread Richard Newman
but, I can't seem to do this with the 'inc' function: user= (binding [inc (fn [y] (+ 2 y))] (inc 44)) 45 Why doesn't this work? Because inc is inlined, and thus isn't mentioned when your binding occurs. (defn inc Returns a number one greater than num. {:inline (fn [x] `(.

Re: let-binding overrides binding-binding

2009-12-24 Thread Tom Hicks
On Dec 24, 6:01 pm, Richard Newman holyg...@gmail.com wrote: but, I can't seem to do this with the 'inc' function: user= (binding [inc (fn [y] (+ 2 y))] (inc 44)) 45 Why doesn't this work? Because inc is inlined, and thus isn't mentioned when your binding   occurs. Thanks

let-binding overrides binding-binding

2009-12-19 Thread Stefan Kamphausen
Hi, just found that a binding-form within a let-form does still use the outer value. user (def *val* root binding) #'user/*val* user (defn print-val [] (println *val* is: *val*)) #'user/print-val user (defn let-vs-binding [] (println beginning: *val*) (let [*val* bound by let]

Re: let-binding overrides binding-binding

2009-12-19 Thread Stephen C. Gilardi
On Dec 19, 2009, at 5:23 PM, Stefan Kamphausen wrote: 1. Is my explanation correct? It is. The binding form operates on the var, it doesn't affect name resolution within the binding form's body. *val* within the body of the binding still resolves to the let-bound local. While *val* is