Re: Pattern matching Vs destructuring?
There are two different concerns in what people refer to as "pattern matching": binding and flow-control. Destructuring only addresses binding. Pattern matching emphasizes flow control, and some binding features typically come along for free with whatever syntax it uses. (But you could in principle have flow control without binding.) On Friday, January 27, 2017 at 1:04:04 AM UTC-6, Didier wrote: > > Some languages have pattern matching, and Clojure is said to not have it > (without a library), but it does have destructuring. > > It seems to me that destructuring is the same as pattern matching, except > that it can only be used inside function arguments, where as pattern > matching can also be used when assigning a value or inside case switch > statements. > > Is that truly the only difference? And if so, why the different > terminology? > > -- 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: Pattern matching Vs destructuring?
On 27 Jan 2017, at 07:04, Didier wrote: > Some languages have pattern matching, and Clojure is said to not have it > (without a library), but it does have destructuring. > > It seems to me that destructuring is the same as pattern matching, except > that it can only be used inside function arguments, Destructuring can be used anywhere there is an implicit or explicit let binding. So you can use destructuring in a let, or in macro arguments: https://clojure.org/guides/destructuring > where as pattern matching can also be used when assigning a value or inside > case switch statements. > > Is that truly the only difference? And if so, why the different terminology? I think the main distinction is that you can’t use destructuring in switching and case statements. Why have a different term? Destructuring does one specific job - picking apart data to allow binding that expresses relationships between values more cleanly. It doesn’t do case statements or switches as pattern matching does. Case statements and switch statements are useful for controlling the circumstances under which code is evaluated, e.g. - you don’t want to evaluate (/ x y) where y is 0. If you don’t need to do that in a particular case, then in that case you don’t need a case or switch statement and your code may be better and clearer without it. And if you don’t need a case or switch statement then you don’t need pattern matching to make it concise. For example, you might have a map with keywords as keys and functions as values and just insert a function by calling the map with the relevant keyword instead of switching or casing. Alan -- 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.
Pattern matching Vs destructuring?
Some languages have pattern matching, and Clojure is said to not have it (without a library), but it does have destructuring. It seems to me that destructuring is the same as pattern matching, except that it can only be used inside function arguments, where as pattern matching can also be used when assigning a value or inside case switch statements. Is that truly the only difference? And if so, why the different terminology? -- 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.