Fork me on GitHub
#clojure-spec
<
2017-05-04
>
slipset07:05:01

Silly might be wrong, but tedious maybe?

slipset07:05:40

what I’d like to be able to state is “I only care about the first argument and it should be a grid ”

dergutemoritz07:05:33

@slipset That's what you're stating with that spec, though, isn't it? 😄 If you feel it's too noisy and/or you're going to use it in many places, you could define a macro that hides that noise.

slipset07:05:44

apart from that, it seems like spec is giving me exactly what I want: the possibility to sprinkle “types” over my program when it’s “done”.

joshjones21:05:58

Namespace myproj/myns.clj contains a function, which requires specs defined in myproj/specs.clj. I have the function fdef'd and it currently sits next to the function itself in myns. However, I'd like to move the function spec away from the function itself. So myns depends on specs, but the fdef'd function depends on knowing about the function itself in myns, so I can't move it to specs. Circular dependency. Where are you putting your spec'd functions (or in general, any of your specs) in your project?

ghadi22:05:45

the specced namespace IMHO should not require the specs

ghadi22:05:10

it was explicit design of clojure.spec that you can spec things you don't own

misha22:05:48

(s/fdef myns/my-fn ...)
without explicitly importing myns in specs, @joshjones

mobileink22:05:09

misha: is that missing a colon?

misha22:05:49

no, its a fully qualified fn name, like clojure.string/blank?

mobileink22:05:32

misha: so you have to require that ns in your spec file? or otherwise define it there? that seems odd, but i'm a relative noob at spec.

misha22:05:45

no, requireing needed. afair, spec just uses fn symbol to register spec, and does not call actual fn, so the actual require'ing is not needed

joshjones22:05:00

many thanks to you both -- @ghadi , by "the specced namespace" you mean myns or specs in my example above?

ghadi22:05:53

yourproj.specs should depend on yourproj.myns, not the other way around, like @misha 's example

misha22:05:57

yeah, myns might not need specs imported unless it uses one for explicit validation as a workflow step

joshjones22:05:26

it does -- (s/assert ::specs/myspec some-data)

joshjones22:05:30

Many examples of using valid?, conform, etc also

misha22:05:46

then either keep fdef's closer to functions, or use fully qualified fn names in fdefs w/o explicit imports

mobileink22:05:44

you only need to require if you want to use an alias, is that correct?

misha22:05:48

mobileink: I'd say: only if you need to call something from that ns, or import for side effects. alias works w/o explicit import (at least it worked for me just now)

mobileink22:05:38

hmm, need to experiment more. i could swear i've used :foo.bar/baz without require or import, but theres a goid chance i misunderstood what i was doing. ;)

misha22:05:07

2 types of specs: for data – keyword (:foo/bar), for functions – symbol (foo/baz)

mobileink22:05:12

i didn't think you could alias an ns without "making" it whether by require or sth else. i.e. just a symbol won't work. but i'm away from my machine, will try later.

mobileink22:05:56

aha, my bad - have not yet worked my way up to fn specs. sorry!

misha22:05:49

I am trying now, and I see no spec ns import required either: I can define specs for functions in foo.specs w/o importing foo.fns, and can use specs for assertions in foo.fns w/o importing foo.specs

mobileink22:05:24

time for me to take another sip from the firehose. not so easy when your lips have already been ripped off!

misha22:05:25

two namespaces, neither imports the other. instrumentation and validation work, because specs get registered in global registry

mobileink22:05:11

i think i assumed reg keys are always kws. bad programmer!

misha22:05:50

I have spec guide open at all times while doing spec development, for quick reference https://clojure.org/guides/spec

mobileink22:05:45

me too - just haven't needed to deal with fns yet. it's hard enough to figure out how to do what i need with maps!

misha22:05:20

the only require use case I can think of now – is google closure compiler advanced optimization, where specs might get dead-code-eliminated. Haven't tried that yet though

mobileink22:05:56

fwiw i just got my clj map specs working in cljs, using cljc code. works like a charm - but haven't done advanced opt yet. shivers

joshjones22:05:55

thanks @misha, very helpful