In Elixir, tuples are used where in the first element is the tag. A similar thing can be done in Clojure using vectors. That much was clear. What bothered me and prompted me to start this thread was I wasn't sure "what" it is I was doing by creating that vector. Was it purely a convention thing? What did the convention mean? It looked weird.
The "aha" moment for me came while watching her talk. The tagged vector is simply a way to represent one case of an open discriminated union. Discriminated unions are a common approach in a language like F#. A function could return an union type Result, with cases Success and Error. And it gels very nicely with pattern matching. In that light, I can acknowledge tagged vectors as a real pattern. Creating records for all these cases wouldn't be worth it in my opinion. Infact one would usually just return a map of values. The caller would branch depending on the presence of an `:err` key. Each branch would have access to the entire map and its not evident which keys are branch specific. The pattern matching approach on the other hand makes explicit the values for each branch. On Sunday, 6 September 2015 07:01:40 UTC+5:30, tbc++ wrote: > > >> Thanks, it helps to know using a tagged vector is a real pattern :) > > I don't know that it's a "real pattern". If I saw code like this in > production I would probably raise quite a stink about it during code > reviews. It's a cute hack, but it is also an abuse of a data structure. Now > when I see [:foo 42] I don't know if I have a vector of data or a tagged > value. It's a better idea IMO to use something like deftype or defrecord to > communicate the type of something. I'd much rather see #foo.bar.Age{:val > 42} than [:foo.bar/age 42]. At least then when I do (type val) I don't get > clojure.lang.PersistentVector. > > Timothy > > -- 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.