On 6 September 2015 at 02:31, Timothy Baldridge <[email protected]>
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.
>
I'll have to disagree with you here. To my mind, tagged literals don't
quite have the same purpose as variants do.
For example, consider a map:
{:foreground #color/rgb "ff0000"
:background #color/rgb "ffffff"}
The hex strings are given a tag to indicate the type of data they contain,
while the keys in the map tell us the purpose of that data.
We clearly wouldn't write something like:
#{#foreground {:val #color/rgb "ff0000"}
#background {:val #color/rgb "ffffff"}}
So given that, if we want to represent a single key/value pair, the most
natural way to do it would be:
[:foreground #color/rgb "ff0000"]
Variants fulfil the same purpose as key/value pairs in a map. The key
denotes a context-sensitive purpose for the data, rather than its type.
- James
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.