Fork me on GitHub

so I'm studying a bit on atoms and I see what deref does but what exactly is happening? What does dereferencing mean? I assume it means the atom is a reference? A reference to a mutable data structure called an atom?


the source of it is very straight forward. you can read it in java and perhaps even easier to read the cljs version


(deftype Atom [state meta validator watches]
  (-deref [_] state)
in cljs and in java:
final AtomicReference state;
public Object deref(){
    return state.get();


it is tricky to discuss precisely because in clojure references mean these constructs for controlled mutation, but the jvm has references and they immutable


so you have to bridge this chasm of conflicting terminology


an atom is an object with a mutable field that can be mutated in an atomic way


deref gets the value of the field


thank you. I'll check these out. with my own searching I am at the (coincidental name) page and it's going over a higher level discussion of what they are and the terminology.


ahh, that was what I was starting to understand. thank you. So when you say object is that in a "object oriented" programming way? Sometimes I wonder what I'm missing out on by mostly starting in the clojure/functional programming world without learning the other stuff. It all seems to reference other languages.


like, it could also be an array of size 1, as long as you can do an atomic compare and set on the first element in the array


"mutated in an atomic way" "atomic compare" but what does "atomic" mean in the programming world?


I guess I meant "mutated in an atomic way" as synonymous with compare and set


compare and set is a very useful primitive for multithreaded programs


there are different forms of it (as cpu instructures which the jvm stuff jits to,)


and it is something like "read this value form this location in memory M, compare it against this other value A and if it matches, write this other value B to this location in memory M"


and it does that atomically, meaning no other executing threads/cpus can see the intermediate values or execute in the middle of that sequence of instructions


I think that was a part of it I was missing. It's because I couldn't explain my confusion. I was seeing why we would use atoms and how they were used (on a beginner level of course) but I would like to understand the entire underlying concept of what "atomic" meant.

hiredman01:02:37 (which redirects to linearizability) is where the atom in clojure comes from, which is entirely different then the atom in most other lisps


good stuff. so is this one way to keep things "thread safe"? I see that pop up when people discuss concurrency. Basically a way so you know multiple...things? aren't changing the value from underneath you.


yes, it is a mechanism for sharing changing information between threads in a controlled way


thanks for the chat and clarifications!


Note though that in cljs it's just a set!. The swap/deref protocol is a great way to organize transformation functionally, but in cljs multi threaded concurrency safety didn't motivate the implementation details.


In JS, "isolates" have run to completion semantics, so effectively the whole environment is atomic.

Disco Dave04:02:16

Hello, I'm in the process of learning clojure. I've been using Joy of Clojure as learning material and for practice. I'm at the point now where I'm learning macros, but I've a hard time to finding practice problems for macros. Can anyone point me in the right place?

Alex Miller (Clojure team)04:02:23

Pick stuff out of core and rewrite it - and, or, when, dotimes, etc


(ns a)

(defprotocol Window
  (height [window])
  (width [window]))

(def window
  (reify Window
    (width [_] (.-innerWidth js/window))
    (height [_] (.-innerHeight js/window))))

((juxt width height) window)
Is there a way to get width and height from window when window is required in another namespace?


Oh…weird. Looks like (a/width a/window) … ? Not sure how that works but looks like it does


that is correct


a protocol is a collection of functions defined in a namespace


so just like if you did a (defn foo [x] ...) in namespace a, you would refer to it in other namespaces like a/foo, the functions in the protocol are the same

👍 5

can someone point me to some references or project examples for creating a full stack Clojure(script) application? I've been looking things up and can't find anything that isn't super outdated, or provides the information I'm looking for 😕


The community has been sharing this a lot towards the end of this week. I haven't tried it myself, but it looks interesting:


It uses the comparatively recent deps.edn for dependencies, and pulls in the more traditional Leiningen for packaging and distribution. For #clojurescript development, it uses the excellent #figwheel, which is certainly best practice as of right now (the other equally viable path being to use #shadow-cljs)


Thanks! I'll definitely check that out!


@ryan.russell011 Edge ... read the docs on how to start your own project.. and look at the tutorial.vent or phonebook folders in edge to see some sample projects ;)


Thanks.. I'll check it out.


@ryan.russell011 is a fullstack clojure + clojurescript application. See the instructions over at for how to run it


Hello, is this the right place to ask questions about clj libs? I have a question about compojure


yup! No need to ask to ask. The friendly folks here will guide you to a more appropriate channel if relevant.


How does one import a spec/def which is defined in another file? I have a spec/def ::networkgraph which I want to import but I don't know how. Doing [backend.netjson.networkgraph-test :refer [networkgraph]] and then using it as ::networkgraph or :networkgraph doesn't work.


cool! So, I'm reading a book on web dev in clojure. It uses wrap-routes the following way:

(def app-routes
    (wrap-routes #'home-routes middleware/wrap-csrf)
    (route/not-found <some 404 response here>))
routes is from compojure.core and home-routes is just a collection of some routes defined with defroutes. The text explains usage of wrap-routes the following way: > The wrap-routes macro is used to ensure that the middleware is applied after the route is resolved, allowing us to restrict it to the home-routes. Had we wrapped these routes directly with (middleware/wrap-csrf home-routes) then the wrap-csrf would end up being applied to any routes defined below home-routes as it's now part of the common middleware chain. I thought about the "common middleware chain" phrase a lot, and couldn't get it at all and I couldn't find any documentation or example on the Internet that would explain this. The implementation of wrap-routes was somewhat hard for me to follow. Finally, I made my own sandbox example and tried using wrap-routes vs direct calling middleware. What I can see, is that compojure has additional behavior to ring handlers: when none of the routes match the requested URI, the handler returns nil. If we wrap this handler with the direct call to some middleware, that middleware will be called on nil and can theoretically return non-nil value, and thus prevent trying other handlers that go after it. Could there be a mistake in the book, or is "common middleware chain" indeed a thing? Or maybe I'm just lost in terminology and the book basically says the same thing I found experimentally? Thank you


i should've warned ya that the weekend traffic can be a little light on here. hopefully someone can help ya out


Hi @UG25K8D5F, welcome! I’m out of practice with ring/compojure, but I just wanted to point you to their respective wikis in case you hadn’t seen them, and to suggest that you might want to repost this in the #ring channel. Good luck!


Not sure if this is the correct way to use specs. Is there another way to use specs which are registered in a different file?


nvm I figured out how registration works


So I have this kind of a folder structure and the spec part is registered as a test root, but for some reason no namespaces inside of spec are recognised.


Weirdly enough Cursive is able to autocomplete correctly for namespaces inside of the spec directory.


The solution was to add the spec dir to :test-paths in the project.clj file

Lucas Barbosa23:02:42

Is there a way to test recursive functions with midje and use provided on the function being tested?

Lucas Barbosa23:02:50

something like:

(j/config->job {:type :composite, :children [.jc1. .jc2.]}) => (j/make-composite-job .j1. .j2.)
        (j/config->job .jc1.) => .j1. :times 1
        (j/config->job .jc2.) => .j2. :times 1)

Lucas Barbosa23:02:00

I am getting the failure message: FAIL at (job_test.clj:74) You never said #'config->job would be called with these arguments: [{:type :composite, :children [.jc1. .jc2.]}]