This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-18
Channels
- # architecture (14)
- # beginners (89)
- # cider (336)
- # cljsrn (2)
- # clojure (181)
- # clojure-berlin (1)
- # clojure-dusseldorf (3)
- # clojure-finland (4)
- # clojure-germany (5)
- # clojure-italy (18)
- # clojure-norway (10)
- # clojure-spec (9)
- # clojure-uk (94)
- # clojurescript (84)
- # cursive (3)
- # data-science (4)
- # datomic (82)
- # emacs (2)
- # events (4)
- # figwheel (1)
- # fulcro (6)
- # graphql (2)
- # hoplon (46)
- # instaparse (24)
- # jobs (9)
- # lein-figwheel (2)
- # luminus (18)
- # lumo (3)
- # mount (1)
- # off-topic (14)
- # onyx (17)
- # parinfer (22)
- # planck (1)
- # protorepl (1)
- # re-frame (50)
- # reagent (7)
- # ring-swagger (6)
- # rum (4)
- # shadow-cljs (94)
- # spacemacs (9)
- # specter (7)
- # tools-deps (2)
- # uncomplicate (4)
- # vim (33)
Silly question, but following along in the https://clojurescript.org/news/2018-03-26-clojurescript-command-line#starting-a-browser-repl I am entering the following
> java -cp cljs.jar cljs.main
Exception in thread "main" java.net.BindException: Address already in use (Bind failed)
Getting pretty much the same thing from https://clojurescript.org/guides/quick-start#clojurescript-compiler as well:
inferno git:(master) ✗ clj --main cljs.main --compile inferno.hello --repl
Exception in thread "main" java.net.BindException: Address already in use (Bind failed)
I'm not sure if the default is easily controllable https://clojurescript.org/reference/repl-options#_browser_repl_options
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.
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 😞
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.
validators are underappreciated
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
🙂 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 https://clojuredocs.org/clojure.core/map 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: https://aphyr.com/tags/Clojure-from-the-ground-up other books worth picking up: Programming Clojure, and (for the more experienced) Joy of Clojure there's also a bunch of video courses on https://purelyfunctional.tv
@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 http://purelyfunctional.tv) 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: https://lispcast.com/hirable-in-clojure/
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.
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?
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.
@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
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
println does realize a sequence
but I’m assuming he’s not using println
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)))
what string do you actually want written?
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")]
(doall
(->> rdr
xml/parse
:content
(filter is-debug-realm?)
first)))
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