Fork me on GitHub
#clojure-spec
<
2016-09-26
>
kestrel714:09:31

Is it possible to define a spec that depends on multiple keys within a map? e.g. ::date-1 must be greater that ::date-2

bcbradley14:09:53

i'm having issues with setting up clojure.spec

bcbradley14:09:02

i'm getting "could not locate clojure/test/check/generators__init.class or clojure/test/check/generators.clj on class path"

bcbradley14:09:04

what does that mean?

bcbradley14:09:22

i'm still getting the error 😕

bcbradley15:09:44

here is my lein

bcbradley15:09:45

(defproject sand "0.0.1-SNAPSHOT" :description "FIXME: write description" :profiles {:dev {:dependencies [[org.clojure/test.check "0.9.0"]]}} :dependencies [[org.clojure/clojure "1.9.0-alpha12"]] :javac-options ["-target" "1.6" "-source" "1.6" "-Xlint:-options"] :aot [sand.core] :main sand.core)

thegeez15:09:10

If you are using Leiningen, you can try to put the dependency at the top level. So put it next to [org.clojure/clojure ...] in :dependencies

bcbradley15:09:47

you mean don't use a dev profile?

bcbradley15:09:55

the function causing the issue is exercise-fn

thegeez15:09:55

Yeah, just to check if that works. You might be using the test.check function in a way that does not fall under leiningen dev profile

thegeez15:09:19

or in a place, rather than a way

bcbradley15:09:36

(defproject sand "0.0.1-SNAPSHOT" :description "FIXME: write description" :dependencies [[org.clojure/clojure "1.9.0-alpha12"] [org.clojure/test.check "0.9.0"]] :javac-options ["-target" "1.6" "-source" "1.6" "-Xlint:-options"] :aot [sand.core] :main sand.core)

bcbradley15:09:41

still no luck

bcbradley15:09:32

i can use clojure.spec/fdef

bcbradley15:09:44

but can't use clojure.spec/exercise-fn

thegeez15:09:52

hmm curious, it works on my machine 😉

bcbradley15:09:16

here is what i'm looking at

seancorfield15:09:43

@bcbradley You’re AOT’ing that namespace so you’re forcing all those specs — including exercise-fn — to run at compile time.

bcbradley15:09:17

i'm sorry for being so new at this 😞

bcbradley15:09:30

the AOT is an acronym i assume

bcbradley15:09:34

what does it stand for?

seancorfield15:09:50

Ahead Of Time (compilation) — relating to the :aot in your project.clj

seancorfield15:09:31

Still, having the exercise-fn call at the top-level of your code means it will be executed whenever that ns is run — put it inside -main so it only runs when you run the -main...

seancorfield15:09:44

Same with generate.

bcbradley15:09:54

ok, i was wondering though

bcbradley15:09:10

if i wanted to make a library how would i test the code? Would i need a main?

seancorfield15:09:43

You’d normally put test code in a separate ns and have it run via one of the test runners.

seancorfield15:09:05

In your project tree, you’ll see a test folder next to src.

seancorfield15:09:26

Hmm, no, in your case you won’t — did you create that project manually?

seancorfield15:09:19

(I’m not familiar with how NightCode creates projects… but normally lein new app myapp will create a test folder as well as a src folder)

bcbradley15:09:38

i just chose "create new console project"

bcbradley15:09:41

i've used lein before

bcbradley15:09:49

but importing a lein project into nightcode gave me some problems

seancorfield15:09:08

I’m surprised (and a bit disappointed) that NightCode doesn’t create a test folder tree for all projects 😞

thegeez15:09:13

I think this is an issue with nightcode. A top level exercise-fn with :gen-class and aot would works

bcbradley15:09:24

i've had trouble finding a good ide for clojure that i like

seancorfield15:09:31

@thegeez Well, if test.check is part of the regular :dependencies yes, but you don’t want that code running at compile time or ns load time...

bcbradley15:09:38

i don't wanna use emacs because its 2016, i don't like eclipse because its sluggish and smells of enterprise, i don't like intellij + cursive because i don't want to pay for it, I don't like netbeans because netbeans. Light table isn't working with clojure 1.9-alpha12

bcbradley15:09:50

it looks like nightcode is my only choice unless i want to rock it in vim

seancorfield15:09:23

The majority of Clojure devs use a form of Emacs according to the annual "State of Clojure" surveys 🙂

bcbradley15:09:44

i'd prefer not to develop carpal tunnel before i turn 30

bcbradley15:09:32

jabbing aside, even after removing the AOT and pulling it into main i get some issues

thegeez15:09:05

@seancorfield yes that setup is not ideal, but more meant to isolate the problem

thegeez15:09:56

@bcbradley now you have the name my-index-of and a spec for my-index-of2

seancorfield15:09:07

@bcbradley Your spec has my-index-of2 but the function … yeah, what @thegeez said 🙂

bcbradley15:09:20

you are right!

bcbradley15:09:23

that fixed it xd

bcbradley15:09:02

i know i'm probably being a pest, but can you explain the difference between clojure.spec and any normal library like clojure.set?

bcbradley15:09:13

i mean in terms of pitfalls,

bcbradley15:09:31

like for instance, i didn't know that i "shouldn't" invoke certain methods or macros at the top level

bcbradley15:09:48

normally i wouldn't invoke anything at the top level in an application, but i figure heck

bcbradley15:09:51

if it works on a repl

bcbradley15:09:56

i'm just trying to learn

bcbradley15:09:00

i need to know what NOT to do

seancorfield15:09:19

In general you don’t want any executable code at the top-level of your namespace.

seancorfield15:09:04

What’s your language background, prior to Clojure? (so we’ll have a frame of reference for what you’re familiar with)

seancorfield15:09:33

And regarding the difference between clojure.spec and "normal" libraries, probably the big one is that there’s a bunch of "testing" stuff in clojure.spec that belongs in test code, where test.check gets brought in via a :dev profile (for REPL and running tests, as opposed to "production" line code). Does that help?

seancorfield15:09:42

The specs themselves — and valid? and conform — are intended for production code, but the generative testing stuff (`generate`, exercise, check) is intended for either interactive use or for running as part of test code.

bcbradley16:09:50

sorry i was away, my language background: C, C++, Java, Python, Javascript and then Clojure

bcbradley16:09:11

i've got 8 years in C, 6 years in C++, 3 years in python, 2 years in javascript and 1 year in clojure

bcbradley16:09:25

i'm in my senior year for software engineering and would like to get a job where the primary language is clojure, or at the very least some other functional oriented job with scala or erlang or whatever

bcbradley16:09:50

i've seen enough of stateful programs to know they are a pitfall

bcbradley16:09:59

and i'm not just espousing things i've heard

bcbradley16:09:06

i've had time to think about it for myself

bcbradley16:09:06

my experience with clojure is probaby summarized best as follows:

bcbradley16:09:30

i know how to use map, reduce, apply partial blah blah blah, i've been doing it for a while

bcbradley16:09:41

when i moved from javascript to clojure i did it for elegance

seancorfield16:09:41

'k so a Clojure namespace produces a class, and all the top-level forms become static initializers in that class… if you think of it in Java / C++ terms, those static initializers get run when a class is loaded, long before any class instance is created… so the same caveats apply.

bcbradley16:09:55

i don't think i'm actually familiar with static initializers

bcbradley16:09:32

well a search on stack overflow was fast enough

bcbradley16:09:40

good to know thats how clojure namespaces work

bcbradley16:09:58

so basically what you are saying is that if I have a bunch of top level forms that depend on some other class already being loaded, but it hasn't been loaded, i'll get a "class nil" error or some such

bcbradley16:09:02

that makes perfect sense

bfabry16:09:43

@bcbradley cursive is free for non-commercial use, fyi

bfabry16:09:12

and in a commercial setting, I can't imagine any company would care about the cost

bfabry17:09:01

it's also rapidly catching up with the the perpetual yak emacs 😛

seancorfield17:09:55

Some of us really like yaks...

dominicm17:09:22

My vim shaving is unmatched in fun vim

Alex Miller (Clojure team)19:09:03

which is mostly fixes and improvements to nilable, which is also probably a little faster

bcbradley21:09:19

i really like nightcode for some reason

bcbradley21:09:26

idk its just not that pretentious

bcbradley21:09:46

its not one thing pretending to be another. Its just a clojure ide. Thats it.