Fork me on GitHub
#beginners
<
2019-08-10
>
bartuka00:08:15

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?

noisesmith00:08:31

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

👍 4
noisesmith00:08:12

and kwargs aren't usually worth the extra trouble imho

Stevan01:08:34

Hi to all

👋 16
seancorfield02:08:49

Welcome @stevannestorovic! Just started learning Clojure?

gerred03:08:37

@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.

gerred03:08:53

a little more difficult given my day to day is working on OSS on kubernetes, but. 😄

4
seancorfield03:08:08

My journey has been all over the map over the last 40 years. And it's touched on Lisp a couple of times.

seancorfield03:08:39

I like Rust. I didn't like Go. Didn't like Ruby either. But languages are very subjective.

Godwin Ko03:08:01

@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 Ko03:08:20

and I hate Java, don’t quite like C++ 😂

seancorfield03:08:28

@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.

seancorfield03:08:57

I was on the C++ Standards Committee for eight years so you can blame some of your dislike on me 🙂

seancorfield03:08:57

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.

seancorfield03:08:09

So... Ruby... bleh 😞 🙂

Godwin Ko03:08:32

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 😂

seancorfield03:08:36

Clojure is as close to a piece of perfect language design as I've found in forty years.

✔️ 20
rich 8
seancorfield03:08:58

Python's fine. I like Python. Such a shame about the 2.7/3.x split tho'.

Crispin07:08:05

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.

Crispin07:08:19

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.

Crispin07:08:02

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.

Crispin07:08:13

was such a joy to learn

Jesse15:08:00

This is my story too.

Godwin Ko04:08:33

Clojure is cool, maybe most Lisp dialects are cool in different aspects

seancorfield04:08:56

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.

seancorfield04:08:22

But Python 3.x is a nice piece of design.

Godwin Ko04:08:15

that’s not gonna happen, legacy app stay much longer than we think or want :thinking_face:

Godwin Ko04:08:44

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.

seancorfield04:08:24

No one warned me. No one had heard of it when I started in 2010 🙂

😂 4
arulpugazh12:08:16

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.

Crispin14:08:07

is ws and wb defined in the cljs? or is it defined in js?

Crispin14:08:00

try (aset (.-Sheets wb) "Test Sheet" ws)

👍 4
Crispin14:08:21

assuming ws and wb are cljs vars, not js variables

mfikes16:08:43

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-access

👍 8
arulpugazh21:08:34

Thanks 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.

murtaza5213:08:53

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 ?

tdantas14:08:53

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 ?

Janne Sauvala15:08:34

I start repl manually from my terminal and connect to to it with Chlorine atom package

Janne Sauvala15:08:12

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)

seancorfield18:08:21

@UJZ6S8YR2 Note: @U0C3SLTHP wants ProtoREPL not Chlorine -- although given that ProtoREPL is pretty much unmaintained these days, I'd probably recommend Chlorine instead.

Janne Sauvala19:08:13

Thanks @seancorfield for correcting me. I easily mix up these different REPLs with each other

tdantas14:08:32

want to connect, from my atom, using protorepl

papachan15:08:05

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

Alex Miller (Clojure team)15:08:48

that's a very old ns from clojure-contrib, so yes

papachan15:08:01

gotcha. thanks

doop16:08:27

Hi folks. I know I’m using with-redefs-fn improperly here but I don’t know what I’m doing wrong.

schmee17:08:31

what is the time namespace?

schmee17:08:35

with-redefs is not the preferred way to do mocking with that lib, check out https://github.com/dm3/clojure.java-time#clocks!

schmee17:08:27

with-redefs has some issues that can make it tricky to use and in particular to understand when it doesn’t work

doop17:08:08

ah okay, let me fiddle around with that. Thanks!

doop17:08:16

@schmee that was it. thank you again!

schmee17:08:51

you’re welcome! 🙂

murtaza5218:08:02

how does refer or refer-clojure differ from require ?

seancorfield18:08:06

@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>)

seancorfield18:08:01

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.

seancorfield18:08:07

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.

seancorfield18:08:50

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.

murtaza5218:08:39

@seancorfield so if I understood correctly require loads a ns and refer interns the vars from that ns.

murtaza5218:08:56

what do you mean by loading a ns ? can you explain that a bit more

seancorfield18:08:06

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])

seancorfield18:08:43

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.

seancorfield18:08:35

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.

seancorfield19:08:48

@murtaza52 Feel free to ask more questions. I have to step away but I expect someone else can pick up and answer those...

murtaza5219:08:46

when you say compile, that means JIT kicking in to compile the bytecode down to machine code ?

murtaza5219:08:05

@seancorfield thanks, your replies were very helpful

seancorfield19:08:11

Compile = compile Clojure source down to JVM byte code.

murtaza5207:08:23

@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.

seancorfield18:08:32

AOT compilation can reduce start up time but for long running processes (servers) that's not really a concern.

seancorfield18:08:51

We do not compile anything at work.

seancorfield18:08:44

Also AOT "leaks". It compiles the specified namespace and anything it statically depends on.

murtaza5205:08:52

@seancorfield thanks, that makes sense

seancorfield19:08:33

The JVM itself handles compilation to native code, as it sees fit (i.e., for hot spots in the code).

cbleslie21:08:50

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.

seancorfield23:08:47

@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=>  

cbleslie23:08:42

I was able to figure out my mistake.

cbleslie23:08:57

I appreciate the extra help @seancorfield

seancorfield23:08:42

Probably should be hh, not HH -- the latter is 24 hour clock

cbleslie23:08:03

Makes sense.

cbleslie23:08:39

/me shakes fist at API’s that use non-standard time formats

cbleslie23:08:19

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.

seancorfield23:08:17

I tried parsing it with the Java Time stuff instead, but LLL won't accept AUG, only Aug, which was a surprise.

seancorfield23:08:52

(and it won't accept aug either)

cbleslie23:08:10

There is no justice.toLowerCase()

cbleslie21:08:58

this is the dataset I am working with: (slurp "")

cbleslie21:08:20

… also I hate nonstandard datestrings.

cbleslie21:08:28

Never mind. 😐

cbleslie21:08:47

It’s always something stupid. ¯\(ツ)

Alex Miller (Clojure team)21:08:41

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

schmee21:08:50

@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

💯 4
cbleslie22:08:53

@schmee if this small script “turns into a thing”, I will totally follow that advice. Bookmarked. Thank you!

Ludwig22:08:33

@alexmiller is there a plan to make a second edition of your wonderful "Clojure Applied" or there is not much change since the publishing?

Alex Miller (Clojure team)22:08:03

Definitely could be updated. But we have no imminent plans to do so :)

Ludwig22:08:39

@alexmiller what would you add or remove (if any) ?

Alex Miller (Clojure team)22:08:17

Would revise some of ch 1 advice on records

Ludwig22:08:52

do you still consider records for domain modeling? or just plain maps with specs is encouraged nowadays?

Alex Miller (Clojure team)22:08:56

Might add some stuff on clj and tools.deps now.

Alex Miller (Clojure team)22:08:30

Records and maps is a balance. I’d tilt back more towards maps now

Alex Miller (Clojure team)22:08:03

Protocol metadata makes maps suitable in more scenarios than before

Ludwig22:08:42

@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?

Alex Miller (Clojure team)22:08:09

Russ’s Getting Clojure is great

👍 4
seancorfield23:08:47

@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=>