Re: pattern matching in clojure
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
Re: pattern matching in clojure
Btw. I'm using [match 0.2.0-SNAPSHOT] and Clojure 1.3 but this import instruction (use '[match.core :only [match]]) from official website of match library doesn't work, only (use '[clojure.core.match.core :only [match ] ]) works and I have given a try to matchure and IT WORKS ;-) But why do I have to define question character as a prefix on destruction variables? This doesn't help in any way and I doubt that is helps matchure too. And here is the contest winning code: http://pastebin.com/w7sKH0Pw Thanks to all and looking to match library being fixed or explained what is wrong with previous code. See you later! On Sep 30, 10:36 am, 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
Re: pattern matching in clojure
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
Re: pattern matching in clojure
Hi Michael On Fri, Sep 30, 2011 at 4:51 PM, Michael Jaaka michael.ja...@googlemail.com wrote: Btw. I'm using [match 0.2.0-SNAPSHOT] and Clojure 1.3 but this import instruction (use '[match.core :only [match]]) from official website of match library doesn't work, only (use '[clojure.core.match.core :only [match ] ]) works Thanks, fixed. and I have given a try to matchure and IT WORKS ;-) Good to hear :) But why do I have to define question character as a prefix on destruction variables? This doesn't help in any way and I doubt that is helps matchure too. From the perspective of core.match, some trickery is involved to know whether to create a new local binding, or to perform an equals test. We look at the surrounding scope at compile time to determine this. Another way would be for the user to provide such information, which seems to be the way matchure has gone, with prefix ? (speculative, I don't actually know the reasons behind the decision) Example: (core.match) (let [x [1 2 3] a 1 b 2 ] (match [x] [[b a c as]] :first ;; b and a are local, perform = test, create new binding c [[a b c as]] :second ;; same, but successful match )) Thanks, Ambrose -- 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
Re: pattern matching in clojure
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
Re: pattern matching in clojure
Thanks! On Sep 30, 11:33 am, Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com wrote: 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
Re: pattern matching in clojure
This probably won't get fixed unless someone does a really good job of convincing me otherwise. Vector notation is reserved for things which support random access. (defn rpn' [ stack symb ] (match [stack symb] [([x y z] :seq) * ] (apply vector (* x y ) z) [([x y z] :seq) + ] (apply vector (+ x y ) z) [x sum ] [ (reduce + x) ] [x y ] (apply vector (read-string y) x) )) Should work just fine. The one approach I might be open to is a variant of match that interprets vector notation as seq notation: (matchs [...] ...) or perhaps (matchv :seq [...] ...) David On Fri, Sep 30, 2011 at 5:04 AM, 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 -- 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
Re: pattern matching in clojure
Hi, core.match might be what you're looking for. (defn append [a b] (match [a b] [[] _] b [[x as] _] (append as (cons x b))) (defn or [b1 b2] (match [b1 b2] [true _] true [_ true] true :else false)) https://github.com/clojure/core.match Thanks, Ambrose On Thu, Sep 29, 2011 at 6: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
Re: pattern matching in clojure
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
Re: pattern matching in clojure
And if you'd actually like a little bit of sugar so that it's really at the level of the function definition - patch welcome! :) David On Thu, Sep 29, 2011 at 6:46 AM, Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com wrote: Hi, core.match might be what you're looking for. (defn append [a b] (match [a b] [[] _] b [[x as] _] (append as (cons x b))) (defn or [b1 b2] (match [b1 b2] [true _] true [_ true] true :else false)) https://github.com/clojure/core.match Thanks, Ambrose On Thu, Sep 29, 2011 at 6: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
Re: pattern matching in clojure
matchure does some funny things to deal with code size, including generating internals fns which will break recur. core.match avoided this problem until quite recently. We've now added backtracking to control code size for certain kinds of pattern matches. However this also conflicts w/ recur, you've reminded me that we need to use the old compilation strategy in the presence of recur :) David On Thu, Sep 29, 2011 at 7:08 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
Re: pattern matching in clojure
On Thu, Sep 29, 2011 at 4:16 PM, Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com wrote: (defn append [a b] (match [a b] [[] _] b [[x as] _] (append as (cons x b))) (defn or [b1 b2] (match [b1 b2] [true _] true [_ true] true :else false)) Does the above code work? Regards, BG -- Baishampayan Ghose b.ghose at gmail.com -- 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
Re: pattern matching in clojure
append is missing a closing paren. It should work. Ambrose On Thu, Sep 29, 2011 at 8:21 PM, Baishampayan Ghose b.gh...@gmail.comwrote: On Thu, Sep 29, 2011 at 4:16 PM, Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com wrote: (defn append [a b] (match [a b] [[] _] b [[x as] _] (append as (cons x b))) (defn or [b1 b2] (match [b1 b2] [true _] true [_ true] true :else false)) Does the above code work? Regards, BG -- Baishampayan Ghose b.ghose at gmail.com -- 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
Re: pattern matching in clojure
On Thu, Sep 29, 2011 at 5:57 PM, Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com wrote: append is missing a closing paren. It should work. Where does `match` come from? I couldn't find it anywhere. Regards, BG -- Baishampayan Ghose b.ghose at gmail.com -- 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
Re: pattern matching in clojure
It's part of core.match. clojure.core.match.core/match https://github.com/clojure/core.match Thanks, Ambrose On Thu, Sep 29, 2011 at 8:28 PM, Baishampayan Ghose b.gh...@gmail.comwrote: On Thu, Sep 29, 2011 at 5:57 PM, Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com wrote: append is missing a closing paren. It should work. Where does `match` come from? I couldn't find it anywhere. Regards, BG -- Baishampayan Ghose b.ghose at gmail.com -- 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
Re: pattern matching in clojure
On Thu, Sep 29, 2011 at 6:00 PM, Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com wrote: It's part of core.match. clojure.core.match.core/match https://github.com/clojure/core.match Sorry Ambrose, I was so stupid, I was looking at core.logic :-) Regards, BG -- Baishampayan Ghose b.ghose at gmail.com -- 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
Re: pattern matching in clojure
In this exchange I've written core.logic when I meant core.match about 4 times xD Ambrose On Thu, Sep 29, 2011 at 8:33 PM, Baishampayan Ghose b.gh...@gmail.comwrote: On Thu, Sep 29, 2011 at 6:00 PM, Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com wrote: It's part of core.match. clojure.core.match.core/match https://github.com/clojure/core.match Sorry Ambrose, I was so stupid, I was looking at core.logic :-) Regards, BG -- Baishampayan Ghose b.ghose at gmail.com -- 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
Re: pattern matching in clojure
In core.logic you do have matche, which is conceptually similar. David On Thu, Sep 29, 2011 at 8:33 AM, Baishampayan Ghose b.gh...@gmail.comwrote: On Thu, Sep 29, 2011 at 6:00 PM, Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com wrote: It's part of core.match. clojure.core.match.core/match https://github.com/clojure/core.match Sorry Ambrose, I was so stupid, I was looking at core.logic :-) Regards, BG -- Baishampayan Ghose b.ghose at gmail.com -- 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
Re: pattern matching in clojure
On Thu, Sep 29, 2011 at 6:06 PM, David Nolen dnolen.li...@gmail.com wrote: In core.logic you do have matche, which is conceptually similar. Right, I knew about `matche` and that added to all the confusion. Regards, BG -- Baishampayan Ghose b.ghose at gmail.com -- 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
Re: pattern matching in clojure
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