Fork me on GitHub

Silly question, but following along in the I am entering the following

> java -cp cljs.jar cljs.main
Exception in thread "main" Address already in use (Bind failed)


How do I diagnose/modify what port is being used and causing an error?


Getting pretty much the same thing from as well:

inferno git:(master) ✗ clj --main cljs.main --compile inferno.hello --repl
Exception in thread "main" Address already in use (Bind failed)


@samedhi By default it is port 9000


@mfikes lsof -n -i4TCP | grep 9000 gives me nothing, am I doing something dumb?


Try telnet 0 9000 as another test to be sure nothing is listening on TCP there


hello-world telnet 0 9000
Connected to .
Escape character is '^]'.


… what have I done?


Hah! Nice. WTF.


You may have some port forwarding set up? Stange.


Got it @mfikes, think you are right, I’ll figure this out, at least I know it is me and not something actually wrong with the process.


Unless you have something odd in your /etc/hosts file. Hrm.


Right, problem is on your end unfortunately. It is unfortunate that you can't easily change the browser REPL port to something other than 9000 😞


You helped me along, I’ll twiddle with it some more, thank you for your help!


FWIW, the port is controllable. I just don't know how to do it via the configuration you can pass via cljs.main. You could clone and build the compiler with a different port, but that might be too much.


Ugh, ok, the key for me was the fact that everytime I kill the PID, a new process spun up at the same port.


That was dumb, but all I really needed to do was stop datomic from starting at startup. 🙂


atoms: do you ever constrain the functions that can be applied to an atom, using a certain code pattern? I know this question sounds a little OO, but code robustness is a concern also for functional programs. I was thinking of a generator function that returns the atom alongside the functions that can be operated on it. This just helps with code organization, does not enforce any restrictions. I find it a necessary balance though.


Admittedly, that is actually not very different from just placing all functions interacting with the atom ― in a namespace dedicated to the atom...


@matan An alternative is to add a :validator to an atom that ensures data in the atom always satisfies some invariant.

👍 8

validators are underappreciated




Well, they have a cost at runtime


Anyway, thanks


Could you please remind me what are my options for mapping a collection without holding to its head and realizing it in full in memory? as I understand every element of the source collection is realized and kept in memory even if the only necessary access to it is during the map operation itself.


map doesn't hold onto the head. Not unless you've wrapped it in a doall to force execution for side effects


And even then, if all you care about is the side effects, use dorun


Or (run! fn coll), which neatly combines (dorun (map fn coll) into a single call


@carr0t close, but dorun and doall are synonyms, and run! is implemented with reduce


never mind i'm wrong

👍 4

dorun and doall are not synonyms


Indeed. doall retains the head. dorun does not


i missed that doall returned coll afterwards 😅


🙂 whoever picked these names for these functions could have arranged them better I guess.


So map does or does not? what's your way of determining that, as it's not heavily document I think? e.g. how do I determine it from their source code?


I looked at but the files on there are generated from the docstrings in the codebase. I mean, I guess I don't really understand your question. map doesn't put responses into a variable or anything. It just returns a result per item in the collection. It the thing that wraps map that decides whether to retain all those responses or not.


But because map is lazy, if you don't wrap it in something then it will probably go "Nothing is using what I return, so I just won't bother executing at all", which is not what you want if you're relying on side effects that occur within the mapped function


FWIW, the above is true in Clojure, but not in ClojureScript, which doesn’t have locals clearing.


Thanks. Very confusing this aspect. Are you certain map doesn't hold to the head? how would I determine this from looking at it's source? maybe I should SO this


hi all, what would be the fastest way to go from 0 to at least mid level in clojure, this in order to land a job using the tool?


@U096TPK1Q this blog series is good too: other books worth picking up: Programming Clojure, and (for the more experienced) Joy of Clojure there's also a bunch of video courses on


oh yes, I have that same url bookmarked


@U61HA86AG I just need to actually make a plan to follow through because my intention is to land a job at some point


Eric Normand (the guy behind also mentors people about jobs. he's on this slack too, you might wanna give him a shout. he's done a lot of thinking on this, see his other website:


Late to the party, I think old books lack much of what's been added and even changed in the language over time. I'd say don't suffice with only old (beloved by some) books. Make a list of topics that you have to learn in parallel: transducers being at the top of the list, and the spec lib also somewhere in the list.


in terms of learning path


many people (including me) began with Clojure for the Brave and True


so do you think that using that I will get at least a grabs with the language ? @joelsanchez?


I have the living clojure book


and was thinking on starting there + the clojure koans


that's probably fine too, I was just citing a very popular and loved book


has anybody had any luck with managing async control flow without using core.async? i started down the cljs-ajax route, but it sure is painful to be back to callback hell


I find Promises to be fine for most use cases, and to usually be a better fit than core.async for most request/response scenarii


In combination with re-frame its pretty easy manageable. you still have one callback for success and one for error, but thats it.


heard good things about Manifold


@U06GS6P1N yes programming in clojurescript has never made appreciate promises so much. i’m thinking about trying httpurr and promesa. i wonder if those funcool people hang out here


@U0677JTQX setting aside all of the complexity re-frame adds, I’m not sure if helps if you have anything but a single async action and a response. callbacks are fine for that usecase, but if you have to do something complicated, like make a network call and then follow it up with subsequent calls based on the return value, the control flow gets blown to pieces really quickly


@U61HA86AG thanks yea i should have mentioned that i’m in cljs not clojure


@U28E43ESX I am undecided on that as I have not used a library like promesa yet. But from a quick glance the only difference I can see is that you chain a function instead of a event listener and that the code is closer together than with re-frame. Is there anything else I am missing?


the error-handling channel is structured like try/catch. with callback/errback, you end up with piles of nested functions and then the errbacks are at the bottom in reverse order


you can also loop without crazy recursion


I see, thank you.


at least, that’s what happens in javascript. i’m hoping promesa works like that


If I'm printing out some data, or writing it to a file, how would I check if a value is a string and if it is, then print it out with single quotes. For example I'm printing the string ASSET How would I add the single quotes so it prints like this 'ASSET'


@jisaacs46: one way to do this would be to make a multimethod on the type of the object, where the method for string returns (str \' s \')


I'm trying to write a string to a file with single quotes like this (->> map-values (map #(str \' % \'))), but all the file has is clojure.lang.LazySeq@19f48b3b how do I get it to actually print out the strings?


map produces a lazy sequence and println doesn't realize the sequence. You could either use mapv to get a non-lazy vector or thread the result into doall @jisaacs46

Alex Miller (Clojure team)18:04:03

println does realize a sequence

Alex Miller (Clojure team)18:04:20

but I’m assuming he’s not using println

Alex Miller (Clojure team)18:04:42

how are you writing the string into the file? spit?


Ah, sorry, that was sloppy of me.


I'm using

(defn write-file [str]
  (with-open [w (  "whfs.sql" :append true)]
    (.write w str)))

Alex Miller (Clojure team)18:04:48

what string do you actually want written?

Alex Miller (Clojure team)18:04:48

like just pr-str on the original map-values may be closer to what you want


It may be, I'll try it. I'm trying to write a bunch of inserts statements, from a vector of maps i retrieved from the database, to a file


I am currently doing something similar lazily parsing xml log files using data.xml. Since doall retains the head, does it mean that all the data is stored in memory anyway at some point?


@alwyn yes - but you can use dorun instead of doall to not retain the head or return a collection if that works


If I have the following code:

(with-open [rdr (io/reader "/home/alwyn/p/olslogF.txt")]
   (->> rdr
        (filter is-debug-realm?)
Would doall retain head to the final sequence or the data as read by the reader?


first already limits it


debug code 🙂 I'm trying to figure out how to actualize that filter function Currently it doesn't work because all it does is trying to fetch specific keys from the 'current' item in the sequence, but I suspect 'current' is not actualized yet.


the item first sees is realized


so if there is no result, then there must be something wrong with my filter function...