Fork me on GitHub
#beginners
<
2021-05-17
>
valerauko02:05:09

Thanks, I didn't know about arrayType. On the other hand Integer/TYPE need eval instead of resolve so not sure how I feel about that...

Ivan Koz02:05:39

@vale could bring them into a closure at function definition, so it only runs once at program start

Ivan Koz02:05:02

(let [get\\convert primitives here] (defn ..)

Juλian (he/him)12:05:38

are there tipps, when one should use defrecord or when they could be too much overhead or overcomplicate things?

NoahTheDuke12:05:03

Records are good when your map is closed (no extra or missing keys), and/or when you want to implement/extend a protocol

Juλian (he/him)12:05:13

and when should I use or not use a protocol?

Juλian (he/him)13:05:22

sorry, will read more about them, maybe I'll understand it then

NoahTheDuke13:05:03

that's a good intro to the topic

pithyless13:05:03

If someone wants to learn more about protocols/multimethods/etc. I found this booklet to be a really good summary of all the pros/cons and when you may want to use which: https://leanpub.com/clojurepolymorphism

👀 4
Souler T15:05:45

I am using d3 in my project and it is possible to show result like this (first pic): with this code (second and third pic): I am a bit confused about the -> syntax here. I know that is https://clojuredocs.org/clojure.core/-%3E It said: • (-> x & forms)

Threads the expr through the forms. Inserts x as the
second item in the first form, making a list of it if it is not a
list already. If there are more forms, inserts the first form as the
second item in second form, etc.
But I want to ask why using (d3/scaleLinear) instead of d3/scaleLinear after -> Why is (d3/scaleLinear) the "x" above, not d3/scaleLinear Is it reasonable to call a methods like (d3/scaleLinear) without any given argument?

andy.fingerhut15:05:31

I am not familiar with d3/scaleLinear. Is it a Clojure function, perhaps?

andy.fingerhut15:05:40

Or from a quick Google search, perhaps it is an interop call to a JavaScript method?

dpsutton15:05:14

it's a function from d3 that takes no arguments. Whoever made that function made it so that it cannot take arguments. So it's pretty reasonable to call it that way.

🍻 1
andy.fingerhut15:05:00

In Clojure, the syntax (d3/scaleLinear) is the way to call a Clojure function, or a JavaScript method via interop, that takes no arguments.

Souler T15:05:51

I used shadow-cljs to import d3.js installed using npm

andy.fingerhut15:05:56

Or to be more precise, it is one good way to do so. There are others, but that is the most commonly used.

Souler T16:05:12

gocha, thanks!

Franco Gasperino18:05:45

when working with threading macros and interleaving -first and -last based on the functions applied, is it more idiomatic to use the as-> macro, or wrap composed in anonymous functions to conform arg positioning?

seancorfield18:05:21

It’s more idiomatic to not mix -> and ->> if you can avoid it.

👆 1
seancorfield18:05:04

See https://stuartsierra.com/tag/dos-and-donts — and the various posts about threading macros.

🙌 1
Juλian (he/him)20:05:33

I'm trying to make my input function nicer by adding a prompt at the beginning, but it doesn't work like I'd expect. Here a minimal example:

(defn prompted-read [prompt]
  (print prompt)
  (read))
When I try it in REPL (clj or lein repl) by calling it like this (prompted-read "Input: "), the prompt is shown only after I enter something. Is there a way to fix this?

seancorfield20:05:04

@julian608 You need flush:

dev=> (defn prompted-read [prompt]
 #_=>   (print prompt)
 #_=>   (flush)
 #_=>   (read))
#'dev/prompted-read
dev=> (prompted-read "Input: ")
Input: 123
123
dev=> 

ghadi20:05:04

@julian608 add a (flush) call after print, flushing only happens after newlines

Juλian (he/him)20:05:28

thanks, @seancorfield and @ghadi - should have known this from other programming languages facepalm

noisesmith13:05:39

I think this is a TTY API issue and not a language issue