Fork me on GitHub
#clojure-spec
<
2017-08-22
>
cddr10:08:29

Is there any way to leverage spec while writing "interpreters/transpilers" like hiccup which seem to be typically implemented by writing a defmethod for each operator. One disadvantage I've noticed about having these things as data is that when authoring the data, you don't get niceties like editor completion that you would get if it was actual code.

cddr13:08:13

Oh. I see this was discussed literally yesterday. Sorry. Are multi-methods one of the cases that aren't easily fixable?

Alex Miller (Clojure team)15:08:21

I think it’s possible to make them work, but haven’t worked on doing so.

cddr07:08:03

It occurred to me today that for my use-case, I think I can work around it with a macro that expands to a (defmethod, defn) pair and then write fspecs against the defn.

yonatanel14:08:59

Is it customary to spec string length with coll-of characters with :count?

Alex Miller (Clojure team)15:08:09

In most cases, I wouldn’t use coll-of for strings as that implies anything that is a sequential view of characters (lists, vectors, seqs)

Alex Miller (Clojure team)15:08:47

prob better to do something like (s/and string? #(= 3 (count %)))

souenzzo18:08:41

@alexmiller is almost possible* specify strings/routing with spec For example: (s/or :nums (s/coll-of #{"1" "2" "3" "4"}) :not-nums (s/coll-of #{"a" "e" "i" "o" "u"})) * with almost possible I mean: you can do with collections of chars. There is plans to do (s/string string-spec) or something like?

Alex Miller (Clojure team)18:08:15

we already have string regex matching - use that

Alex Miller (Clojure team)18:08:39

spec’s regex stuff will never be anywhere near as fast or as full-featured as the excellent regex engine already built into java

Alex Miller (Clojure team)18:08:18

if you want gen, Gary’s regex stuff in test.chuck is pretty cool

seancorfield19:08:13

Yeah, a big +1 for test.chuck's regex generator -- we love that!

souenzzo20:08:19

I thought about using the specifications to do string routing. Trying to do something better than bidi, I realized spec would do that. Bidi gives you a data/dsl form do describe strings [[:foo :bar :my-path1] [:foo :my-path0]] Then, bidi "conform" this string and returns the conformed [:my-path1 {:foo "username" :bar "project-name"}] It's very close to spec (s/or :my-path (s/cat :foo string-wo-bar? :bar string-wo-bar?))...

dealy20:08:16

Hi, I'm just getting started w/spec. I just added clojure 1.9 to my project.clj and immediately get a huge spec error at startup. Is it usually difficult to upgrade a project from 1.8 to 1.9?

hiredman20:08:36

kind of hard to say, in general, anything that spec complains about 1.9 is also broken in 1.8, 1.8 just isn't checking

seancorfield20:08:21

@dealy One place to start looking is https://dev.clojure.org/display/design/Errors+found+with+core+specs which lists libraries that clojure.spec found bugs in, most of which have been fixed/updated.

dealy20:08:51

It seems to be failing on my require statement, the error msg doesn't hlep much: In: [2] val: (quote :as) fails at: [:args :exclude :op :spec] predicate: #{:exclude}

dealy20:08:01

it repeats that error several times

dealy20:08:21

its on the first line of the first file it tries to compile

seancorfield20:08:47

What does your require look like?

dealy20:08:09

its about 21 lines, should I post it here?

seancorfield20:08:27

Use a snippet (via the + button on the left)

hiredman20:08:07

are you using core.async I vaguely recall there being a gnarly bug that looks something like that if you aren't on the latest or so release

dealy20:08:21

yes using core.async

seancorfield20:08:22

Interesting -- core.async isn't listed on that page above so I guess it had been updated/fixed before that page was created -- good catch @hiredman !

seancorfield21:08:01

Yeah, I suspect a lot of people working with core.async in any way are adding it as an exclusion and pulling in a new version directly.

hiredman20:08:26

so that is an example of a similar issue, fixed by bumping core.async versions

dealy20:08:34

well that helped some, at least the program went further before spewing errors, I didn't realize that there were gonna be these kinds of problems just upgrading to 1.9 ugh

Alex Miller (Clojure team)21:08:17

1.9 has specs on core that will find errors that were silently ignored in the past. so, it’s good! but also frustrating at times. many of the most popular libs have been fixed up long ago.

dealy20:08:56

any idea what is causing this: Error refreshing environment: java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V, compiling:(closure.clj:100:1) I'm using cljs 1.9.908

hiredman20:08:41

you should check your build tool for conflicting versions of whatever com.google.common comes from

dealy21:08:13

it was guava, upgrading to the latest cljs caused a conflict I guess, its working now

Oliver George23:08:07

It might be mild OCD but I find it quite inconvenient to come up with qualified keywords when writing function specs.

Oliver George23:08:37

I think what I want is a more adhoc/flexible way to create aliases.

Alex Miller (Clojure team)23:08:48

Likely coming in the future (but not 1.9)

souenzzo15:08:32

Waiting to 2.o

Oliver George23:08:52

For example:

(s/def ::session (s/keys :req [:oauth2/csrf-token]))
(s/def ::params (s/keys :req-un [::code ::params]))
(s/fdef oauth2-success :args (s/cat :req (s/keys :req-un [::params ::session])))

Oliver George23:08:23

This is a ring handler. If I want to spec several handlers in one namespace the ::params key needs to be unique.

Oliver George23:08:47

So I end up wanting qualified keywords with a namespace unique to the function symbol

Oliver George23:08:01

e.g. ::oauth-success/params

Oliver George23:08:38

I can do it long hand. :my-app.handlers.oauth-success/params

Oliver George23:08:15

In CLJ I can declare the alias (but not CLJS) and then do ::oauth-success/params but even that is pretty heavy handed.