Fork me on GitHub
#clojure-spec
<
2023-02-21
>
stopa17:02:05

A noob naming question, that I guess doesn't really have an answer, but I thought I'd try anyways. Consider:

(s/def ::triple (s/cat :e string? :a string? :v string?))
Now I may call this vec a triple:
["e", "a", "v"]
But what should I call the (s/conform ::triple) version of it?
{:e "e", :a "a", :v "v"}
I am thinking parsed-triple or conformed-triple, but I wonder if there's a current idiom. If I have some functions that work on one type vs another, I worry about wonky names.

delaguardo17:02:15

named-triple

delaguardo17:02:32

or just record

nbardiuk17:02:44

https://clojure.org/guides/spec#_collections mentions Conforms to map with named keys based on the cat tags . I would add more naming options like tagged-triple or named-triple . Python has named tuple which looks similar

stopa17:02:21

Oo nice idea! Thanks team

serioga08:02:13

named tuple may be confusing as far as element order is not garanteed

delaguardo09:02:15

Why should order matter after conforming with the spec?

dgb2309:02:23

If you're already using tripple as a name, then name it tagged or named tripple as well instead of tuple IMO

dgb2309:02:30

tripple is more precise than tuple

serioga09:02:43

The word tuple means “finite ordered list”. https://en.wikipedia.org/wiki/Tuple It can be vague that named predicate drops the “ordered” characteristic. :-)

☝️ 2
dgb2309:02:57

From the same article: > Many programming languages offer an alternative to tuples, known as https://en.wikipedia.org/wiki/Record_(computer_science), featuring unordered elements accessed by label.

serioga09:02:07

btw python's named tuples are ordered and support access by index.

dgb2309:02:25

record tripple or just record seem to be good names 🙂

delaguardo09:02:30

It is even matching with clojure.core/record 🙂