Hello ! I think, this branch (without :<< empty?))
(match [l prefix] * [_ ([] :seq)] true* is already checking that prefix is empty. Have a nice day, Jon On 16 July 2015 at 23:06, Rastko Soskic <rss...@gmail.com> wrote: > Hi, I am getting familiar with Clojure's core.match and > simply starting with something simple and familar (some Scala match > expressions) > and translating that to core.match variant: > Check out this function which checks whether sequence starts with another: > > def startsWith[A](l: List[A], prefix: List[A]): Boolean = (l,prefix) match > { > case (_,Nil) => true > case (Cons(h,t),Cons(h2,t2)) if h == h2 => startsWith(t, t2) > case _ => false > } > > and my core.match attempt which works but I am not really sure > about it as wiki page is not yet exhaustive enough: > > (defn starts-with [l prefix] > (match [l prefix] > * [_ ([] :seq :<< empty?)] true* > [([h & t] :seq) ([h2 & t2] :seq)] (if (= h h2) > (starts-with t t2) > false) > :else false)) > > second and third one are nothing special, former is just match > continuation. > First one is of particular interest for me... > Matching to Nil sequence in clojure is not appropriate as empty sequence > simply is not nil > whereas it is handled differently in scala. > > What I wanted here is to check with empty? function if second argument > (prefix) > is empty sequence... Like I said...it works but I am not sure if there is > better > way to achieve function application to :seq pattern. I don't need to > destructure or bind > that to any particular var just to check if it is empty. > > Any tip, suggestion or critic is welcome and appreciated. > > Thanks in advance. > > -- > 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.