Re: def partial vs let partial
It's because the value of the + is captured when the partial is created (or when the var is implicitly derefed). The value of the var is implicitly captured (via deref) at the point where it appears in the form. It's a bit of a complex topic, but this blog post I wrote a few months ago may help a bit: http://blog.cognitect.com/blog/2016/9/15/works-on-my-machine-understanding-var-bindings-and-roots On Thu, Dec 1, 2016 at 1:30 PM, Matthew Hamrick wrote: > I'm confused by the following code. > Could someone explain to me why the def-ed partial has different behavior > to the letted one? > This is especially confusing to me since the #() special form one works as > I expect. > > (def sum-partial-def (partial reduce +)) > > (let [sum-partial (partial reduce +) > sum-# #(reduce + %1) > nums [1 2 3 4]] > [(sum-partial-def nums) >(reduce + nums) >(sum-# nums) >(sum-partial nums)]) ;; => [10 10 10 10] > > (with-redefs [+ (fn [a b] > (.add (.add (BigInteger. (str a)) > (BigInteger. (str b))) > (BigInteger/ONE)))] > (let [sum-partial (partial reduce +) > sum-# #(reduce + %1) > nums [1 2 3 4]] > [(sum-partial-def nums) > (reduce + nums) > (sum-# nums) > (sum-partial nums)])) ;; => [10 13 13 13] > > Thanks, > Matt > > -- > 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. > -- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth) -- 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: def partial vs let partial
Sum-partial-def gets the original + definition because it is evaluated first, if you want late binding, try (partial reduce (var +)). On Dec 1, 2016 4:05 PM, "Matthew Hamrick" wrote: > I'm confused by the following code. > Could someone explain to me why the def-ed partial has different behavior > to the letted one? > This is especially confusing to me since the #() special form one works as > I expect. > > (def sum-partial-def (partial reduce +)) > > (let [sum-partial (partial reduce +) > sum-# #(reduce + %1) > nums [1 2 3 4]] > [(sum-partial-def nums) >(reduce + nums) >(sum-# nums) >(sum-partial nums)]) ;; => [10 10 10 10] > > (with-redefs [+ (fn [a b] > (.add (.add (BigInteger. (str a)) > (BigInteger. (str b))) > (BigInteger/ONE)))] > (let [sum-partial (partial reduce +) > sum-# #(reduce + %1) > nums [1 2 3 4]] > [(sum-partial-def nums) > (reduce + nums) > (sum-# nums) > (sum-partial nums)])) ;; => [10 13 13 13] > > Thanks, > Matt > > -- > 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.
def partial vs let partial
I'm confused by the following code. Could someone explain to me why the def-ed partial has different behavior to the letted one? This is especially confusing to me since the #() special form one works as I expect. (def sum-partial-def (partial reduce +)) (let [sum-partial (partial reduce +) sum-# #(reduce + %1) nums [1 2 3 4]] [(sum-partial-def nums) (reduce + nums) (sum-# nums) (sum-partial nums)]) ;; => [10 10 10 10] (with-redefs [+ (fn [a b] (.add (.add (BigInteger. (str a)) (BigInteger. (str b))) (BigInteger/ONE)))] (let [sum-partial (partial reduce +) sum-# #(reduce + %1) nums [1 2 3 4]] [(sum-partial-def nums) (reduce + nums) (sum-# nums) (sum-partial nums)])) ;; => [10 13 13 13] Thanks, Matt -- 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: Clojure as a first programming language?
It's a question simply stated with an answer that depends on a lot of things. And, as is often the case with the person giving an answer, without asking other people I can only relate it to my own experiences with clojure and programming in general. The fun and freeing thing about clojure is the flexible ways it allows you to program and think about programming challenges. There's a number of reasons that make this true. Languages I've used in the past at times felt like their design was limiting, usually in the form of making easy things easy and hard things harder than necessary. Maybe they provided too much "help" and turned inner workings into a difficult-to-know black box, or they provided concurrency building blocks without providing a safe framework to prevent a novice programmer from shooting themselves in the foot, or they were designed in such a way that locking in developer mindshare was a primary motivator. I don't think clojure has these problems. Diving into a new language requires good learning resources, particularly in the ways you find most natural to use. Are you self-sufficient? Is documentation enough or would it be faster and more useful to be able to ask someone questions? Do you have any higher education in programming? Buy some clojure books and spend time with them. The mailing list, IRC and slack, et. al. can all be resources for specific questions but more general questions (even this one) can be more difficult to answer. Pick something you want to make and explore what different languages have to offer and you'll naturally find one that resonates with you. I love clojure. It's not perfect but it's still smarter than I am, which I appreciate. It rarely gets in my way. On Thu, Dec 1, 2016 at 12:22 PM, Nur Azhar wrote: > Hi, > > it's almost 8 years later and I am going to ask these same question since > it wasn't really answered > > Thanks for taking the time to read. I’m interested in trying out Clojure >> for my first programming language--at least, the first programming language >> in which I intend to commit myself to becoming proficient. >> http://stackoverflow.com/questions/10509283/clojure-as- >> a-first-programming-language >> > I hope someone replies > > On Tuesday, December 1, 2009 at 1:38:58 PM UTC+8, Towle wrote: >> >> Hi all, >> >> Thanks for taking the time to read my post. I'm interested to get some >> opinions from experienced Clojure programmers on whether the language >> would be a good first language to learn, or rather to learn in-depth. >> I have minimal experienced with more common languages like Java, HTML, >> and C++, but having the personality I do, felt compelled to shop >> around a bit before choosing a first language to learn seriously on a >> deep and intuitive level-- perhaps my odd notion of there being a >> connection between a programmer and the first language s/he >> understands on that high of a level. So after shopping around >> thoroughly and picking up bits about on theoretical computer science >> and the history of programming languages, I decided to pick up a Lisp; >> I'm intrigued by the greater concept/idea behind the Lisp family of >> languages. >> >> After a long while trying to figure out which of the Lisps would be a >> good first choice, I stumbled across Clojure and immediately thought >> it a brilliant idea, conceding of course that at my current level of >> knowledge, I likely have no idea what a brilliant idea in computer >> programming looks like. Regardless, it still feels brilliant. >> >> As I see it, among other features of the language, the idea of a Lisp >> designed to be a capable choice for "real-world" code applications, >> that is a Lisp which embodies the spirit of that family of languages >> yet one which resolves many of the "practicality" complaints which >> stand as hurdles on a Lisp's path to real-world use. For my situation, >> that of a student who wants both a) to learn a first language I can >> have a real, intellectual appreciation for and b) to begin the journey >> to "expertise" in a language it would be practical to code web >> applications in. >> >> So, Clojure programmers, am I wrong? Should I pass on Clojure in favor >> of another langauge? Or learn Common Lisp or Scheme first, then try my >> hand at Clojure? Am I mistaken for a different reason? Or perhaps >> there are some criteria I should consider before diving in? >> >> Thanks in advance, and again for taking the time to read. >> --Towle >> > -- > 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
Re: Clojure as a first programming language?
Hi, it's almost 8 years later and I am going to ask these same question since it wasn't really answered Thanks for taking the time to read. I’m interested in trying out Clojure > for my first programming language--at least, the first programming language > in which I intend to commit myself to becoming proficient. > > http://stackoverflow.com/questions/10509283/clojure-as-a-first-programming-language > I hope someone replies On Tuesday, December 1, 2009 at 1:38:58 PM UTC+8, Towle wrote: > > Hi all, > > Thanks for taking the time to read my post. I'm interested to get some > opinions from experienced Clojure programmers on whether the language > would be a good first language to learn, or rather to learn in-depth. > I have minimal experienced with more common languages like Java, HTML, > and C++, but having the personality I do, felt compelled to shop > around a bit before choosing a first language to learn seriously on a > deep and intuitive level-- perhaps my odd notion of there being a > connection between a programmer and the first language s/he > understands on that high of a level. So after shopping around > thoroughly and picking up bits about on theoretical computer science > and the history of programming languages, I decided to pick up a Lisp; > I'm intrigued by the greater concept/idea behind the Lisp family of > languages. > > After a long while trying to figure out which of the Lisps would be a > good first choice, I stumbled across Clojure and immediately thought > it a brilliant idea, conceding of course that at my current level of > knowledge, I likely have no idea what a brilliant idea in computer > programming looks like. Regardless, it still feels brilliant. > > As I see it, among other features of the language, the idea of a Lisp > designed to be a capable choice for "real-world" code applications, > that is a Lisp which embodies the spirit of that family of languages > yet one which resolves many of the "practicality" complaints which > stand as hurdles on a Lisp's path to real-world use. For my situation, > that of a student who wants both a) to learn a first language I can > have a real, intellectual appreciation for and b) to begin the journey > to "expertise" in a language it would be practical to code web > applications in. > > So, Clojure programmers, am I wrong? Should I pass on Clojure in favor > of another langauge? Or learn Common Lisp or Scheme first, then try my > hand at Clojure? Am I mistaken for a different reason? Or perhaps > there are some criteria I should consider before diving in? > > Thanks in advance, and again for taking the time to read. > --Towle > -- 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.