Fork me on GitHub
#clojure-spec
<
2018-04-05
>
Alex Miller (Clojure team)01:04:37

And generally that implies you are prob doing something you shouldn’t as you then have a spec that is impure.

flyboarder14:04:18

Could you explain an impure spec? I am trying to generate a spec from some nested data

Charles Fourdrignier16:04:48

If I want to spec’ data from a CSV file, what would be the best strategy ? Should I describe it as a tuple ? Or should I convert it to a map then spec the map itself ? (I don’t find any article or blog post on this subject.)

Alex Miller (Clojure team)16:04:18

a csv file is inherently a collection of collections of strings

Alex Miller (Clojure team)16:04:36

and thus very uninteresting to spec and unlikely to tell you much

Alex Miller (Clojure team)16:04:14

I suspect from an app perspective, it is far more interesting to convert to maps (coercing data if needed) and to spec the result, which is the data your app actually uses

Charles Fourdrignier16:04:54

Thanks ! Tuples was my first intuition, but some reading changes my mind and your response finish to convince me.

Drew Verlee20:04:53

I have some unqualified keywords that conceptually map to some specs i have created. Whats the suggested way to convert a unqualified keyword to a qualified one so i can exercise it (generate data) or conversely, use a generator on a unqualified keyword. I feel i could do this my pulling things apart and putting them back together with strings but im guessing im missing an obvious exisiting way to handle this:

(str *ns* "/" :unqalified)

manderson21:04:30

@drewverlee any reason that you couldn't just add namespaces to your unqualified keywords? If you do want to go back and forth, the best way I can think of is as follows (perhaps someone knows of something better):

(def +qualified+
  (keyword (-> *ns* ns-name str) (name :unqualified)))
=> #'user/+qualified+

+qualified+
=> :user/unqualified

(-> +qualified+ name keyword)
=> :unqualified

Drew Verlee13:04:37

no reason, just wonder if thats the right approach.

manderson14:04:28

Spec is opinionated about using namespaced keywords (see the rationale doc on this: https://clojure.org/about/spec#_global_namespaced_names_are_more_important), so in general, if you are using spec, I've found that it is best to follow this pattern.