Fork me on GitHub
#clojure-spec
<
2016-06-06
>
manderson12:06:53

Curious if there has been any thought given to adding a doc string parameter to clojure.spec/def like there is in clojure.core/def? I understand the spec should be self-explanatory, but it's nice to be able to capture additional information/description about the spec. I've found myself adding comments that would be nice to have as doc strings that could then also be parsed programatically.

Alex Miller (Clojure team)12:06:40

yes, there has been thought about it

Alex Miller (Clojure team)12:06:35

not sure if anyone noticed, but you can now call doc with a registered spec keyword to get it's spec definition. that's a place that docstring could show up.

Alex Miller (Clojure team)12:06:56

but it's something Rich is still thinking about afaik

manderson12:06:02

cool, thanks Alex. I think the built in doc string could be really useful.

manderson12:06:10

Also, didn't notice the doc addition. That's great.

mike_ananev13:06:00

Hello all! I learn clojurescript. Today I discovered that clojurescript doesn't throw Exceptions in code above like Clojure. Can clojure.spec help in such situations? I use reagent and want prevent state updating from using inappropriate function.

nwjsmith14:06:55

@mike1452: Hey Mike, welcome to ClojureScript! clojure.spec can definitely help you here:

gfredericks15:06:28

nwjsmith: the spec needs to be (s/cat :arg integer?)' instead of just integer?`, right?

gfredericks15:06:37

s/integer/number/

nwjsmith15:06:19

That's what I thought at first, but maybe this is a situation where a pred is implicitly converted to a spec?

gfredericks15:06:37

I guess I'll just go try it :)

nwjsmith15:06:53

when passed to valid? or conform, predicates will be implicitly converted to a spec, which I think is what happens here.

gfredericks15:06:20

it throws an error when you call it with a number as well

gfredericks15:06:35

it's not about spec vs predicate it's about spec-for-a-single-arg vs spec-for-an-arglist

nwjsmith15:06:15

@mike1452 looks like the example I gave above is wrong. The call to s/fdef should be:

(s/fdef inc :args (s/cat :x number?))
thanks @gfredericks

angusiguess18:06:58

Is there a nice way to spec the following?

angusiguess18:06:21

"I want a map of arbitrary keywords whose values must conform to some predicate"

angusiguess18:06:15

@nwjsmith: Beauty, thank you 🙂

wilkerlucio22:06:07

with clojure.spec I'm finding myself wanting to use some kind long namespaces for my keywords, they are just getting to be a borden to write, for example (s/keys :req [:my-app.some-ns.clock/at, :my-app.some-ns.clock/namespace]), the namespace my-app.some-ns.clock doesn't actually exists, it's just helpful to avoid name clashing, I'm writing those in the my-app.some-ns

wilkerlucio22:06:53

I was thinking that would be useful to be able to alias those namespaces so they can be used in a simpler way, for example:

wilkerlucio22:06:26

it's possible to alias like this with the currently clojure features?

noonian22:06:46

I believe if you require a namespace like (ns my-ns (:require [my-app.some-ns.clock :as clock])) you can use ::clock/foo and it will resolve to :my-app.some-ns.clock.

wilkerlucio22:06:11

@noonian: yes, but that would require me to create a file with that namespace, that's what I would like to avoid

noonian22:06:07

Ah got it, sorry I didn’t read your message carefully enough.

wilkerlucio22:06:46

thanks @jr, I had saw that one, and I agree that will help, but only on map cases... when you are setting it as keywords for lists (on the s/keys for example) you can't use that, so we would still have to repeat the typing, I believe aliasing is a more general solution here that could be very useful with long namespaces

hiredman22:06:50

you don't actually need to create a file now

hiredman22:06:08

user=> (create-ns 'my-app.some-ns.clock)
#object[clojure.lang.Namespace 0x3b7d3a38 "my-app.some-ns.clock"]
user=> (alias 'clock 'my-app.some-ns.clock)
nil
user=> ::clock/foo
:my-app.some-ns.clock/foo
user=> 

wilkerlucio23:06:51

@hiredman: thanks, I'm going to try that soon, do you think that can work on cljs as well?

hiredman23:06:48

cljs is a different kettle of fish, I am not sure

wilkerlucio23:06:36

yeah, I have to fix some compilation issues here and then I'll try it out