This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # beginners (50)
- # cider (112)
- # cljs-dev (7)
- # clojure (34)
- # clojure-brasil (1)
- # clojure-greece (4)
- # clojure-italy (8)
- # clojure-nl (14)
- # clojure-russia (4)
- # clojure-uk (94)
- # clojurescript (96)
- # clojutre (5)
- # cloverage (1)
- # cursive (5)
- # datomic (59)
- # docs (53)
- # figwheel (4)
- # fulcro (1)
- # hoplon (1)
- # hyperfiddle (3)
- # jobs (3)
- # luminus (6)
- # nyc (3)
- # off-topic (9)
- # onyx (3)
- # overtone (4)
- # re-frame (2)
- # reagent (16)
- # reitit (9)
- # ring (2)
- # ring-swagger (1)
- # rum (1)
- # shadow-cljs (81)
- # spacemacs (14)
- # specter (12)
- # sql (1)
- # tools-deps (2)
- # vim (110)
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
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.
Also, before you start developing, get your hands on some functional IDE, and try developing incrementally, with REPL plugged in. Helps a lot.
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 🙂
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]]
@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. 😉
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 https://github.com/Provisdom/spectomic )
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
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?
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
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
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
(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
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)