Fork me on GitHub
#beginners
<
2018-07-10
>
JanisOlex10:07:48

Hello 🙂 I am new here 🙂 With questions.

JanisOlex10:07:50

Is it natural for Clojure to create the data structures as nested maps/lists with keys and make functions to operate on them, or it is ok to do it through classes?

JanisOlex10:07:30

for example - I want to create game, which will contain players, moves, scores etc. is it like one fat map with all that info inside it under different keys?

dimitrijer10:07:09

Yeah, it’s idiomatic for Clojure to use structures to pass data around. In fact, classes aren’t really used in Clojure (except for Java interop). Take a look at protocols or multimethods for getting different behaviors based on data shape/contents. Back to passing data around - If performance becomes an issue (it probably won’t), you can make data wrappers with deftype and defrecord

JanisOlex10:07:31

Thanks. So essentially I can start building my "game" even I don't know much about Clojure, but already know how to make maps/sets/lists and fill the structures with data and then start thinking on functions to operate on the data 🙂 Good - sounds good.

dimitrijer10:07:40

Sure, you only need to know basic structures, some standard library functions and how to define your own functions 🙂

JanisOlex10:07:12

well that's why I picked non-trivial task (game) to start building, so the clojure becomes more tangible... Already passed all the clojure koans, so concepts are understood basically. Also read through "Brave and True" book, now - obviously have to do actual coding

dimitrijer10:07:45

I highly recommend The Joy of Clojure book, Brave and True is nice, but short (and somewhat hyped. IMHO). Good luck to you, just ask if you need anything.

JanisOlex10:07:22

another book I am trying to go through (has more to web dev too) - Living Clojure

JanisOlex10:07:31

Thanks, will look into the Joy

dimitrijer10:07:37

Also, before you start developing, get your hands on some functional IDE, and try developing incrementally, with REPL plugged in. Helps a lot.

JanisOlex10:07:49

gave Cursive

👍 4
JanisOlex10:07:15

and yes, without REPL I wouldn't be able to do anything useful, that's how I was doing all those koans

JanisOlex10:07:03

programming and IT is not alien to me, i am not n00b in programming in general, I am n00b in Clojure... need to get my brain revamp 🙂

JanisOlex10:07:24

and it is soooooo hard to get out of Java and OOP imperative habits of thinking

stunami11:07:32

Bit confused maybe someone can advise, Im working through the web development with clojure book, and Ive got some validation code that resides in a cljc namespace

stunami11:07:26

im trying to refer that in a clj namespace, and the example just seems to have the “bare” path which would be the same as my-app.namespace, ie [my-app.validation :refer [registration-errors]]

stunami11:07:08

neither the IDE (Cursive) nor the REPL are able to resolve it

stunami11:07:36

verbatim from the book and the .validation is a cljc namespace under

stunami11:07:39

picture-gallery-a/src/cljc/picture_gallery/validation.cljc

stunami11:07:53

Right… ns declaration in validate was incorrect. Nothing to see here. 🙂

stunami11:07:25

So, to answer my own question, no need to do anything different to refer cljc ns’s

felbit11:07:36

@stunami I am just through the book myself. If you get stuck somewhere else, just shoot me a DM, maybe we can figure it out together. 😉

👍 4
Oleh K.19:07:56

Hi! What is the best way to fill a datomic database with test data?

eggsyntax01:07:24

There's not a built-in way that I'm aware of; personally I like to write specs for my datomic data, and then you can use clojure.spec.gen.alpha/sample to generate as much matching data as you like.

eggsyntax01:07:09

(you can also derive the datomic schema from those specs, but that's a much more advanced exercise. If you're interested, take a look at https://github.com/Provisdom/spectomic )

kazesberger20:07:53

making my first babysteps with spec (actually im just running into error message using the specced spandex api https://github.com/mpenet/spandex/blob/master/src/clj/qbits/spandex/spec.clj :-D) having trouble interpreting the error message

noisesmith20:07:05

your defn doesn't have an arg list in square brackets (an arg vector)

👍 4
noisesmith20:07:36

it's actually saying that, but there's so much extra info that it gets lost in there

noisesmith20:07:49

> Call to clojure.core/defn did not conform to spec: ... fails spec: :clojure.core.specs.alpha/arg-list ... predicate: vector?

kazesberger20:07:19

omg 😵 plz forget, dear internet. thx a lot

noisesmith20:07:52

it's a real problem with how spec works right now - the right info is in there, but it's in a big pile of irrelevant stuff most of the time

noisesmith20:07:11

there's been high energy debate about how best to go forward with that

kazesberger20:07:27

i actually read that vector-thing, but in the message but i'm not used to this code is data thing. in my head those vector brackets of functions are "just syntax" i just searched for some vector? predicates in the spandex spec but obviously this didnt lead to anything useful xD

noisesmith20:07:07

yeah, very few things in clojure are syntax :D

noisesmith20:07:50

(and even the syntaxes are just data on the layer they are implemented)

kazesberger20:07:54

one additional question on this topic

kazesberger20:07:58

is this the kind of stuff i need to give me some guidance/hints for those "syntax-ish" stuff like the function arg vector brackets? https://github.com/jonase/eastwood

noisesmith20:07:28

eastwood will definitely help you catch things clojure wouldn't normally catch

noisesmith20:07:05

(eg. defining an fn to take one number of args, calling it with another - eastwood recognizes that in your source, clojure doesn't catch it until runtime when the call happens)

noisesmith20:07:25

I'm not sure if its error for defn missing an arg vector is an improvement - you could check

kazesberger20:07:10

definitely will do that 🙂

noisesmith20:07:13

but it's worth using as long as you don't have weird code that makes it show too many false positives

noisesmith20:07:41

(and arguably making your code less weird is an acceptable price to pay for getting better info from eastwood)

kazesberger20:07:25

hehe. my code is definitely in the weird section. 😂

kazesberger20:07:46

thanks a lot!

eggsyntax01:07:24

There's not a built-in way that I'm aware of; personally I like to write specs for my datomic data, and then you can use clojure.spec.gen.alpha/sample to generate as much matching data as you like.