I've opened an issue concerning this bug: http://dev.clojure.org/jira/browse/MATCH-21
Ambrose On Fri, Sep 30, 2011 at 5:04 PM, Ambrose Bonnaire-Sergeant < abonnaireserge...@gmail.com> wrote: > There's a problem with destructuring lists (seems like a bug). > > If stack is always a vector, it works. > > (defn rpn' [ stack symb ] > (match [stack symb] > [ [x y & z ] "*" ] (apply vector (* x y ) z) > [ [x y & z ] "+" ] (apply vector (+ x y ) z) > [ x "sum" ] [ (reduce + x) ] > [ x y ] (apply vector (read-string y) x) )) > > (defn calculator'[ input ] > (first (reduce rpn' [] (re-seq #"\S+" input)))) > > (calculator' " 1 2 10 2 3 + * sum ") > ;=> 53 > > core.match isn't well road tested yet, still early days. > > Thanks! > Ambrose > > On Fri, Sep 30, 2011 at 4:36 PM, Michael Jaaka < > michael.ja...@googlemail.com> wrote: > >> Thanks for feedback. But now I'm came across a problem. I'm studying >> "Learn You a Haskell for Great Good!" and I'm on chapter "Functionally >> Solving Problems" reading "Reverse Polish notation calculator". >> I wanted to write it in Clojure. So instead of: >> http://pastebin.com/QzhbyD6d >> I wrote: http://pastebin.com/fsChN96D >> >> But as you can see the first try doesn't work as expected. >> The destruction of stack doesn't work as expected. >> Expectation is written below as let expression. >> >> Anyone? >> >> >> >> On Sep 30, 6:56 am, Kevin Downey <redc...@gmail.com> wrote: >> > Last I checked matchjure generates fns which break recur (there is an >> issue >> > open for it). Trading recursion for matching seems like a bad deal, I >> > recommend using match instead. >> > On Sep 29, 2011 4:32 AM, "Christian Pohlmann" < >> chr.pohlm...@googlemail.com> >> > wrote: >> > >> > >> > >> > >> > >> > >> > >> > > Additionally to core.match there is also matchure [1] which comes with >> > > a defn-match that can be used like this: >> > >> > > (defn-match choose >> > > ([_ 0] 1) >> > > ([0 _] 0) >> > > ([?n ?k] (+ (choose (dec n) (dec k)) (choose (dec n) k)))) >> > >> > > This makes defining functions fairly close to what you're used from >> > Haskell. >> > >> > > [1]https://github.com/dcolthorp/matchure >> > >> > > Christian >> > >> > > On Thu, Sep 29, 2011 at 12:03 PM, Michael Jaaka >> > > <michael.ja...@googlemail.com> wrote: >> > >> Hi! >> > >> > >> Is there any way to define function with pattern matching in function >> > >> signature as it is in haskell? >> > >> > >> Bye! >> > >> > >> -- >> > >> 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 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 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 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