pattern matching in clojure

2011-09-29 Thread Michael Jaaka
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 memb

Re: pattern matching in clojure

2011-09-29 Thread Ambrose Bonnaire-Sergeant
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 T

Re: pattern matching in clojure

2011-09-29 Thread Christian Pohlmann
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]

Re: pattern matching in clojure

2011-09-29 Thread David Nolen
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

Re: pattern matching in clojure

2011-09-29 Thread David Nolen
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'

Re: pattern matching in clojure

2011-09-29 Thread Baishampayan Ghose
On Thu, Sep 29, 2011 at 4:16 PM, Ambrose Bonnaire-Sergeant 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

Re: pattern matching in clojure

2011-09-29 Thread Ambrose Bonnaire-Sergeant
append is missing a closing paren. It should work. Ambrose On Thu, Sep 29, 2011 at 8:21 PM, Baishampayan Ghose wrote: > On Thu, Sep 29, 2011 at 4:16 PM, Ambrose Bonnaire-Sergeant > wrote: > > (defn append [a b] > > (match [a b] > > [[] _] b > > [[x & as] _] (append as (cons x b)))

Re: pattern matching in clojure

2011-09-29 Thread Baishampayan Ghose
On Thu, Sep 29, 2011 at 5:57 PM, Ambrose Bonnaire-Sergeant 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 t

Re: pattern matching in clojure

2011-09-29 Thread Ambrose Bonnaire-Sergeant
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 wrote: > On Thu, Sep 29, 2011 at 5:57 PM, Ambrose Bonnaire-Sergeant > wrote: > > append is missing a closing paren. > > It should wo

Re: pattern matching in clojure

2011-09-29 Thread Baishampayan Ghose
On Thu, Sep 29, 2011 at 6:00 PM, Ambrose Bonnaire-Sergeant 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 r

Re: pattern matching in clojure

2011-09-29 Thread Ambrose Bonnaire-Sergeant
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 wrote: > On Thu, Sep 29, 2011 at 6:00 PM, Ambrose Bonnaire-Sergeant > wrote: > > It's part of core.match. > > clojure.core.match.core/match > > https://g

Re: pattern matching in clojure

2011-09-29 Thread David Nolen
In core.logic you do have matche, which is conceptually similar. David On Thu, Sep 29, 2011 at 8:33 AM, Baishampayan Ghose wrote: > On Thu, Sep 29, 2011 at 6:00 PM, Ambrose Bonnaire-Sergeant > wrote: > > It's part of core.match. > > clojure.core.match.core/match > > https://github.com/clojure/c

Re: pattern matching in clojure

2011-09-29 Thread Baishampayan Ghose
On Thu, Sep 29, 2011 at 6:06 PM, David Nolen 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 subscri

Re: pattern matching in clojure

2011-09-29 Thread Kevin Downey
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" wrote: > Additionally to core.match there is also matchure [1] which comes

Re: pattern matching in clojure

2011-09-30 Thread Michael Jaaka
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://pa

Re: pattern matching in clojure

2011-09-30 Thread Michael Jaaka
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

Re: pattern matching in clojure

2011-09-30 Thread Ambrose Bonnaire-Sergeant
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) ]

Re: pattern matching in clojure

2011-09-30 Thread Ambrose Bonnaire-Sergeant
Hi Michael On Fri, Sep 30, 2011 at 4:51 PM, Michael Jaaka 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 [ma

Re: pattern matching in clojure

2011-09-30 Thread Ambrose Bonnaire-Sergeant
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 wor

Re: pattern matching in clojure

2011-09-30 Thread Michael Jaaka
Thanks! On Sep 30, 11:33 am, Ambrose Bonnaire-Sergeant 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

Re: pattern matching in clojure

2011-09-30 Thread David Nolen
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)