Fork me on GitHub
#clojure-spec
<
2017-05-24
>
weavejester15:05:20

Should instrument report the name of the function that failed in the ex-data?

weavejester15:05:03

It reports the function name in the exception message, but it’s missing from the exception’s data.

Alex Miller (Clojure team)15:05:16

example would help, but feel free to file something about itk

Alex Miller (Clojure team)15:05:03

@weavejester just looked at an example - definitely yes

weavejester15:05:14

Ah, I was just about to post one 🙂

weavejester15:05:30

Shall I add a JIRA report, @alexmiller ?

Alex Miller (Clojure team)15:05:19

if you patch it, I will screen it too :)

Alex Miller (Clojure team)15:05:11

btw, enjoyed your defn podcast episode

weavejester15:05:20

Ah thanks 🙂

Alex Miller (Clojure team)16:05:19

I assume this is obvious, but patch will be against the spec.alpha lib, not core clojure repo

weavejester16:05:41

Sorry, I couldn’t find the spec.alpha lib in the project list when I created the issue.

stathissideris16:05:48

is there any support for string keys in s/keys? or any plan to support them later?

ghadi17:05:38

no @stathissideris -- s/keys needs things that are globally registered (keywords/specs)

Alex Miller (Clojure team)18:05:53

@weavejester you filed it in the right place - spec issues are being managed in CLJ, just meant that the patch would be on a different repo

jfntn18:05:05

What’s an idiomatic way to spec args for a multi-arity function where the longer arities only add new arguments to the shorter ones? Say the full args vector is [a b c ...] but you have aritites with defaults that only take [a], or [a b] etc?

stathissideris18:05:16

@jfntn I think you either do (s/or :arity1 (s/cat ..) :arity2 (s/cat ...) :arity3 (s/cat)) or (s/cat x y (s/? w z))

stathissideris18:05:27

not sure which is more idiomatic

stathissideris18:05:56

actually it’s not s/?

jfntn18:05:09

Ah that works: (s/valid? (s/cat :a string? :b string? :c (s/? string?)) ["a" "b"])

stathissideris18:05:36

yeah, but I think s/? is for a single predicate

jfntn18:05:42

Was looking to remove the duplication from s/or so I think that’s what I’m after

jfntn18:05:49

Seems to do what I expect: (s/explain (s/cat :a string? :b string? :c (s/? string?) :d (s/? string?)) ["a" "b" "c" :d])

stathissideris18:05:45

@jfntn ok, but if for some reason you had arities 2 and 4, you’d say

stathissideris18:05:47

(s/cat :a string? :b string? :rest (s/? (s/cat :c string? :d string?)))

stathissideris18:05:27

which is valid for ["a" "b"] and ["a" "b" "c" "d"] but not for 3 strings

stathissideris18:05:51

this works because the nested s/cat does not imply a nested sequence

stathissideris18:05:45

if you want nesting, you need to wrap it with a s/spec:

stathissideris18:05:50

(s/valid? (s/cat :a string? :b string? :rest (s/? (s/spec (s/cat :c string? :d string?)))) ["a" "b"])

stathissideris18:05:59

(s/valid? (s/cat :a string? :b string? :rest (s/? (s/spec (s/cat :c string? :d string?)))) ["a" "b" ["c" "d"]])

stephenmhopper19:05:41

Hi everybody, what’s the best way to use clojure.spec with Clojure 1.8?

stephenmhopper19:05:48

Is there a clojar for that?

mattly20:05:23

is there any way to dynamically provide arguments from a collection to spec/or ? It's a macro so I can't use apply

donaldball20:05:32

mattly: I have used eval for similar purposes:

(doseq [[spec-kw field-spec desc] fields]
  (eval `(s/def ~spec-kw ~(build-internal-spec field-spec))))

mattly20:05:56

yeah, the individual specs I haven't had problems with, what I need is to validate that a value in a map conforms to one of possibly 100 specs

donaldball20:05:38

Well, a way you could do that is to use eval to build the s/or form you want

mattly21:05:52

hm, thanks

arohner21:05:19

is there a way to get the default generator, so I can update it?

arohner21:05:06

(s/with-gen :foo #(gen/fmap update (s/gen :foo)))

arohner21:05:18

I guess I can

(s/def :foo* …) (s/def :foo (s/with-gen :foo* ...))

Alex Miller (Clojure team)21:05:28

Yeah, having a shorthand for this case is something I think would be useful