Fork me on GitHub
#clojure-spec
<
2018-08-13
>
lilactown01:08:31

I think I understand. thank you for the thorough explanation!

🤝 4
triss15:08:51

so I’ve got a few namespaces - each one responsible for managing the contents of particular type of map. Is there a convention in clojure for what to call your “constructer” method? Do you name it after the type of the type of object you’re going to create (already in the namespace?) or use a word like create or construct?

guy15:08:08

(def job {:name "some job"}) like that you mean?

guy15:08:49

(defn job [some-args] ...)

lilactown15:08:37

@triss I think this is a better discussion for #clojure , but I try and elide create or make whenever possible

triss15:08:01

ah yes you’re probably right re: #clojure…

triss15:08:06

the annoying thing is most of my constructers just do (s/conform ::definition args)

triss15:08:41

but that’s way too much to type…

lilactown15:08:06

I see what you’re saying though. If i had a particular namespace, like my-app.job and in there were all functions that work on the job entity type, then I would probably just have a create fn

triss15:08:07

or is it… maybe I should just call (s/conform directly) in other namespaces?

lilactown15:08:24

that might be my OCaml bleeding through tho

lilactown15:08:31

it’s probably better to hide the fact that all you’re doing is s/conform in case you ever want to do more?

triss15:08:06

that was my thinking I guess

triss15:08:16

but it is very rare I do more these days…

mikerod19:08:19

Is it necessary to forward-declare specs that are referenced from other specs in a case such as mutually recursive specs? Contrived example:

(s/def ::a
  (s/map-of keyword? (s/or :b ::b :str string?))

(s/def ::b
  (s/map-of keyword? ::a))

taylor19:08:03

not in my experience, as long as they're both registered by the time you use them

mikerod19:08:06

I believe, at least in some circumstances, that the forward-use of a spec isn’t resolved until later anyways, so the forward declaration isn’t needed (maybe I’m wrong)

mikerod19:08:19

@taylor that is what I thought I was seeing as well

mikerod19:08:47

and looking at how the references are used in a various impl’s I checked in clojure.spec.alpha it seemed like it was ok

mikerod19:08:58

but I haven’t seen any direct discussions on it really. I’ve seen at least one posts in the wild that did something like

;; Forward-declaration, replaced later
(s/def ::b any?)

(s/def ::a
  (s/map-of keyword? (s/or :b ::b :str string?))

(s/def ::b
  (s/map-of keyword? ::a))
but that doesn’t seem necessary

taylor19:08:27

agree, seems unnecessary

taylor19:08:12

the keyword names are like "pointers" to the actual specs that get stored in the spec registry, so as long as the pointer points to a registered spec by the time it's used, I'd assume all's well