Fork me on GitHub
Kyle Brodie01:05:47

Whats the best way to spec numbers as strings so something like "12.53" will be generated?


It has specs that accept strings or longs and generate as strings that are parseable as longs. Should give you something to work from.

Kyle Brodie02:05:00

@seancorfield Thank you! That library looks very helpful. I might have to write my own date though because mine are "YYYY-MM-DD". Unless "yyyy-M-d" is the right format for zero padded in java-time


Yeah, it'll do zero-padded. And you want yyyy and d lowercase for dates.

Kira McLean11:05:09

Hi there.. I’m just getting started with spec, have a somewhat noob question that I’m having trouble finding an answer to: Is it possible to have two different specs for the value of a given un-qualified keyword? I.e. I have a map and I know that the values might have different requirements in different contexts, but I would like to keep re-using the same key. So I have specs like this (`fs` is [datoteka.core :as fs] ):

(s/def ::path fs/path?)
(s/def ::html-path (s/and ::path (partial matches-ext "html")))
(s/def ::content string?)

;; This one is great -- checks my maps like {:path ,,, :content ,,,}
(s/def ::page (s/keys :req-un [::path ::content]))

;; Here is the issue: I want to check a map that also has the keys [:path 
;; :content], not one with an html-path key
(s/def ::html-page (s/keys :req-un [:path ::html-path ::content])) 
In the ::html-page spec I want :path to match the html-path spec but for the key to still be called :path . Is this possible?


If you define two specs, :a.b.c/path and :x.y.z/path you can use them to spec unqualified keys in different maps

Kira McLean16:05:19

Makes perfect sense, thanks.

David Pham18:05:12

Are there good library to use with clojure.spec? 🙂


@neo2551 you can find spec libraries (along with other libraries) here:

Kira McLean20:05:07

Can you write a function spec for a multi-method? If so, any chance anyone can share an example of this somewhere?


You can spec the method, but afaik not the implementations


Caveat with fspec on mm: instrumentation changes the type to a fn, so future defmethods will fail with a type error


You need to unstrument before evaluating more defmethods

Kira McLean23:05:48

Interesting.. good to know. Yeah I’m curious about whether it’s possible to spec the implementations of a multimethod. I couldn’t find any examples online, but so far I’ve found with clojure that doesn’t always mean it’s not possible.

Alex Miller (Clojure team)23:05:52

You can spec the dispatch method used in the mm if that’s useful

Kira McLean23:05:49

That’s something! But good to know, thanks!


I’m not sure if this is useful or relevant to your goals, but:

Kira McLean21:05:18

Ah this is really cool! Never thought of separating out the args and mm to spec separately. Perhaps a little unorthodox or is this normal? But definitely interesting. Thanks!