Fork me on GitHub
#clojure-spec
<
2016-09-19
>
jasonjckn06:09:43

is there an inverse of s/conform ?

jeroenvandijk08:09:41

@jasonjckn yes, it’s s/unform

jasonjckn17:09:04

@jeroenvandijk thanks! I ran head smack right into that issue yesterday 🙂

jasonjckn17:09:20

@jeroenvandijk but used s/conformer to get around it

Alex Miller (Clojure team)17:09:39

btw, that issue is imo a problem with conform, not unform :)

jasonjckn17:09:02

aside from that issue is making macro writing a joy

Alex Miller (Clojure team)17:09:14

are you using conform to destructure input?

Alex Miller (Clojure team)17:09:40

I haven’t seen too many people doing that yet but our presumption has been that it would remove a lot of fragile gross code

jasonjckn17:09:46

(let [ast (s/conform ::defui forms)
        ast2 (ast-transform ast)
        out (s/unform ::defui ast2)

jasonjckn17:09:52

total joy 🙂

Alex Miller (Clojure team)17:09:02

cool, that’s great to hear about

jasonjckn17:09:20

here's my ast transformer still toying with this code

(defn ast-transform [ast]
  (letfn [(walk-fn [xf]
            (-> xf
                (match->
                 {:protocol (_ :guard #(static-symbs (name %)))}
                 (assoc :static? 'static)

                 {:method-name 'render :args [this om-props] :body body}
                 (assoc :args [this]
                        :body `[(let [~(s/unform ::cs/binding-form om-props)
                                      (om.next/props ~(s/unform ::cs/binding-form this))]
                                  ~@body)])

                 :else (*recur-walk*))))]
    (walk-explicit-recur ast walk-fn)))

jasonjckn17:09:33

the pattern is walking + match->

jasonjckn17:09:40

I implemented match->

patrkris17:09:36

Is clojure.spec a suitable tool for validating JSON formatted HTTP request bodies? I am asking because the pervasive use of namespaced keywords specs seems to conflict with that

patrkris17:09:49

I mean using namespaced keywords as object keys in JSON seems unnatural

Alex Miller (Clojure team)17:09:53

you can use s/keys with :req-un and :opt-un for that

Alex Miller (Clojure team)17:09:10

many people are and it’s been discussed a number of times here - you might find it in the back chat

patrkris17:09:51

That was what I thought about doing myself. But then I started thinking about nested maps and whether that would end up posing a problem. Probably not 🙂 You mentioned some time ago that you were thinking about adding a way to "rename" keys in s/keys. Any development on that?

Alex Miller (Clojure team)17:09:42

nope. up to Rich whether that idea comes back, so I’m not sure if it will.

liamd21:09:50

i’m not able to import clojure.spec.gen into my clojurescript project? any idea why?

liamd21:09:07

No such namespace: clojure.spec.gen, could not locate clojure/spec/gen.cljs, clojure/spec/gen.cljc, or Closure namespace “clojure.spec.gen”

Geoffrey Gaillard21:09:23

Hi @liamd, according to the current clojure.spec guide, it seems you need to add [org.clojure/test.check "0.9.0"] to your :dev profile in your project.clj

:profiles {:dev {:dependencies [[org.clojure/test.check "0.9.0"]]}}
Or with boot
(set-env!
 :dependencies '[[org.clojure/test.check "0.9.0" :scope "test"]])
Did it solve your problem ?

hiredman21:09:59

looking at the clojurescript repo, that namespace doesn't exist

hiredman21:09:28

it doesn't seem to have been ported

liamd21:09:53

i did add test.check to my dependencies

liamd21:09:01

not under dev for now, but that shouldn’t matter right?

Geoffrey Gaillard21:09:46

Ho my bad, sorry. Try with [cljs.spec.impl.gen :as gen]

liamd21:09:02

that seems to have gotten rid of the import error, but i’m still not sure which things to use to get spec generation working

liamd21:09:02

now it’s

clojure.test.check.generators/simple-type-printable does not exist, clojure.test.check.generators never required

liamd21:09:19

so looks like i need to require clojure.test.check.generators

liamd21:09:42

ah got it!

Geoffrey Gaillard21:09:35

Yes same for me, sometime I need cljs.spec.impl.gen, sometime clojure.test.check.generators. But this code

(gen/sample (s/gen int?))
effectively require clojure.test.check.generators :as gen and cljs.spec :as s