This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-08-10
Channels
- # announcements (4)
- # beginners (111)
- # calva (12)
- # cider (10)
- # cljdoc (1)
- # cljs-dev (7)
- # cljsrn (4)
- # clojure (38)
- # clojure-houston (1)
- # clojure-serbia (3)
- # clojure-spec (22)
- # clojure-uk (26)
- # clojurescript (4)
- # cursive (1)
- # data-science (1)
- # datomic (12)
- # klipse (1)
- # off-topic (25)
- # pathom (9)
- # protorepl (3)
- # quil (4)
- # shadow-cljs (43)
- # tools-deps (24)
I have some functions that are responsible for the orchestration (I will refer as comp-fns
) of some other fns, however these comp-fns
receive several arguments (6+) what is the more idiomatic way to handle this situation? Pass the parameters as hash-maps?
yeah, with more than four args I like a hash map with named keys, as it's impossible to tell if the args are right just by looking when there's that many
and kwargs aren't usually worth the extra trouble imho
Welcome @stevannestorovic! Just started learning Clojure?
@seancorfield not my welcome to take, but funny you ask that as I've been asking myself a lot of things lately. over the past 13 years I've gone ruby -> learning clojure -> go -> ok, i like clojure -> rust -> ok, i'm going to build everything I can build in clojure. which, written out, sounds funny and almost a denial of where terrible orange site comments would tell you to go. just saying, 6 years ago was the best time to pick up clojure, now is the second best time.
a little more difficult given my day to day is working on OSS on kubernetes, but. š
My journey has been all over the map over the last 40 years. And it's touched on Lisp a couple of times.
I like Rust. I didn't like Go. Didn't like Ruby either. But languages are very subjective.
@seancorfield Curious to ask whatās the major reason that you donāt like Ruby? btw, iāve been programming Ruby for past few years, now just start stepping into Clojure/Clojurescript :face_with_raised_eyebrow:
@godwin.ko Purely subjective. I've been a language designer/implementer since the very early 80's so I have very strong opinions on what makes a readable, maintainable language -- and Ruby fails miserably on my criteria.
I was on the C++ Standards Committee for eight years so you can blame some of your dislike on me š
I co-wrote one of the first three ANSI-validated C compilers. I wrote a C++ compiler front end. I designed an ML-like language/interpreter back in the early 80's.
So... Ruby... bleh š š
but Ruby/Python is good for newcomers with no computer science background, just hack and using whatever popular framework/library, and it works most of the time š
Clojure is as close to a piece of perfect language design as I've found in forty years.

Python's fine. I like Python. Such a shame about the 2.7/3.x split tho'.
I liked python too. Used it professionally for many many years. But when they broke compatability going to 3 (even in really silly ways that was totally unnecessary like changing .iteritems to .iter) and I needed to start a new project, it was no longer a python 2 vs python 3 question. As I couldn't just use my old code anyway, it became a python 3 vs all the other cool new langauges than had appeared since python 2 had been released.
and a senior engineer I was working with at the time and really respected told me to learn clojure as he considered it a "next step" coming from a ruby or python background. I'm super glad he did. I haven't looked back.
In fact learning clojure then gave me feelings very reminiscent of when I learnt python 2 back in the day. A feeling of speed and of ease. Of the joy of working with something very clean and well designed. Except more so. Like saying goodbye to classes and the endless "dunder" methods.
I attended PyCon 2013 since it was local and it all looked so promising. They said "about five years" for everything to be cut over to 3.x. Sigh.
But Python 3.x is a nice piece of design.
thatās not gonna happen, legacy app stay much longer than we think or want :thinking_face:
itās funny that, when I talk to every local developers that Iām jumping into Clojure, almost everyone warned me that nobody is using it, hard to recruit developers, hard to train team members, ⦠etc.
Hi guys, I have a basic cljs->js interop question: I need to assign something to an array element, but couldn't find how to do it. I am trying to use sheetjs and trying to use this line
wb.Sheets["Test Sheet"] = ws;
.
I've tried
(set! (.-Sheets wb "Test Sheet" ) ws)
and (set! (.-Sheets "Test Sheet" wb ) ws)
but figwheel throws error.
Instead of aset
(which operates on JavaScript arrays using numeric indices), consider
(goog.object/set (.-Sheets wb) "Test Sheet" ws)
otherwise warnings or errors will be emitted if :checked-arrays
is enabled.
See more at https://clojurescript.org/news/2017-07-14-checked-array-accessThanks for the help guys š @U1QQJJK89 yes, those are defined in a let closure above, which I didn't include it here @U04VDQDDY the goog.object method worked fine! For the benefit of future cljs beginners, can we add this into a common place, probably in Clojurescript cheatsheet? Because, it's difficult to find the above article through googling.
I can add / update multiple values in a map using both (assoc {:a 2} :a 5 :b 5)
and (merge {:a 2} {:a 5 :b 5)
. Which one should be preferred ?
Either is fine
hey guys, Iām using atom + protorepl .. starting my new code to use clj tools deps .. how you guys starting the nrepl on your projects ?
I start repl manually from my terminal and connect to to it with Chlorine atom package
I donāt have the exact clj alias atm (Iām on mobile) but I followed Sean Corfieldās setup to start repl (you can find it from here https://github.com/seancorfield/dot-clojure)
@UJZ6S8YR2 Note: @U0C3SLTHP wants ProtoREPL not Chlorine -- although given that ProtoREPL is pretty much unmaintained these days, I'd probably recommend Chlorine instead.
Thanks @seancorfield for correcting me. I easily mix up these different REPLs with each other
is this https://clojure.github.io/core.incubator/clojure.core.strint-api.html deprecated?
I have this:
No such namespace: clojure.core.strint, could not locate clojure/core/strint.cljs, clojure/core/strint.cljc, or JavaScript source providing "clojure.core.strint" in file src/guestbook/core.cljs
that's a very old ns from clojure-contrib, so yes
Hi folks. I know Iām using with-redefs-fn improperly here but I donāt know what Iām doing wrong.
with-redefs is not the preferred way to do mocking with that lib, check out https://github.com/dm3/clojure.java-time#clocks!
with-redefs has some issues that can make it tricky to use and in particular to understand when it doesnāt work
@murtaza52 require
loads a namespace (if it isn't already loaded) and can give the namespace a local alias (`:as`) and can also intern symbols from that namespace into the current namespace (so they are accessible without the alias) -- using :refer
. refer
itself does the same as require
's :refer
option -- but does not load the namespace first. refer-clojure
is a shorthand for (refer 'clojure.core <options>)
It's very rare to use the refer
function since you normally need to load a namespace before first use, and it's easier to combine the require
and refer
operations in a single require
with the :refer
option.
refer-clojure
is generally only needed when you are deliberately defining symbols in your namespace that "shadow" something in clojure.core
and want to avoid the warning the compiler gives about replacing symbol definitions.
For example, https://github.com/clojure/clojure/blob/master/src/clj/clojure/string.clj#L42 -- since clojure.string
defines replace
and reverse
that shadow (hide/replace) those two definitions in clojure.core
.
Does that help @murtaza52?
@seancorfield so if I understood correctly require
loads a ns and refer
interns the vars from that ns.
Yes. And (require '[some-lib.ns :refer [func1 func2]])
is the same as (require 'some-lib.ns)
followed by (refer 'some-lib.ns :only ['func1 'func2])
Loading a namespace -- if it has been loaded yet, find the expected matching file on disk, read it in and compile it form by form.
So, in general (require '[some-lib.ns])
would look for some_lib/ns.clj
somewhere on the class path (e.g., in src
) and then load & compile it.
@murtaza52 Feel free to ask more questions. I have to step away but I expect someone else can pick up and answer those...
when you say compile, that means JIT kicking in to compile the bytecode down to machine code ?
@seancorfield thanks, your replies were very helpful
Compile = compile Clojure source down to JVM byte code.
@seancorfield so what does the lein compile
step do ? Does it only compile AOT classes, and rest is left as source code ?
Wouldnāt it make more sense to compile all source code to java byte code at build time, before the jar is deployed to production ? This will reduce latency when code is executed at run time.
AOT compilation can reduce start up time but for long running processes (servers) that's not really a concern.
We do not compile anything at work.
Also AOT "leaks". It compiles the specified namespace and anything it statically depends on.
@seancorfield thanks, that makes sense
The JVM itself handles compilation to native code, as it sees fit (i.e., for hot spots in the code).
Dear cool Clojure peopleā¦
(.parse (java.text.SimpleDateFormat. "MMM/dd/yy H a") "AUG/10/2019 04:22 AM")
any clue on how to parse this date format correctly? I am not sure how to get this date formatter to work.
@cameronleslie I didn't see anyone answer this so
user=> (.parse (java.text.SimpleDateFormat. "MMM/dd/yyyy HH:mm a") "AUG/10/2019 04:22 AM")
#inst "2019-08-10T11:22:00.000-00:00"
user=>
I appreciate the extra help @seancorfield
Probably should be hh
, not HH
-- the latter is 24 hour clock
Iām new to LISPs, but i āgetā most of whatās going on; but Iāve never used Java, so itās weird using the interop stuff. I find myself trying to translate whatās going on with the Java methods in my head.
I tried parsing it with the Java Time stuff instead, but LLL
won't accept AUG
, only Aug
, which was a surprise.
(and it won't accept aug
either)
just fyi, that SimpleDateFormat object is not thread-safe - you're fine there because you're creating a new one every time, but don't like put it in a def and use it from multiple threads
@cameronleslie I recommend using https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html and other java.time
over java.util.Date and SimpleDateFormat, if thatās possible in your case
@schmee if this small script āturns into a thingā, I will totally follow that advice. Bookmarked. Thank you!
@alexmiller is there a plan to make a second edition of your wonderful "Clojure Applied" or there is not much change since the publishing?
Definitely could be updated. But we have no imminent plans to do so :)
@alexmiller what would you add or remove (if any) ?
Would revise some of ch 1 advice on records
Would add spec
do you still consider records for domain modeling? or just plain maps with specs is encouraged nowadays?
Might add some stuff on clj and tools.deps now.
Records and maps is a balance. Iād tilt back more towards maps now
Protocol metadata makes maps suitable in more scenarios than before
@alexmiller thanks, I'm using Programming Clojure 3rd and Clojure applied as learning resource, do you have any recomendations for a " updated , idiomatic and /or best practices " book?
@alexmiller thanks!!
@cameronleslie I didn't see anyone answer this so
user=> (.parse (java.text.SimpleDateFormat. "MMM/dd/yyyy HH:mm a") "AUG/10/2019 04:22 AM")
#inst "2019-08-10T11:22:00.000-00:00"
user=>