Fork me on GitHub

Hello 🙂 I am new here 🙂 With questions.


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?


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?


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


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.


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


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


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.


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


Thanks, will look into the Joy


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


gave Cursive

👍 4

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


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 🙂


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


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


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]]


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


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




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


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


@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?


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.


(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 )


making my first babysteps with spec (actually im just running into error message using the specced spandex api :-D) having trouble interpreting the error message


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

👍 4

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


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


omg 😵 plz forget, dear internet. thx a lot


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


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


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


yeah, very few things in clojure are syntax :D


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


one additional question on this topic


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?


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


(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)


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


definitely will do that 🙂


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


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


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


thanks a lot!


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.