beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
zackteo 2021-03-25T06:40:38.004400Z

On a linux system, where does lein install dependencies to, if i use sudo . Was trying to see if the steps for a tutorial wasn't working because I was not running in sudo. I understand that dependencies are normally installed in /home/.m2

seancorfield 2021-03-25T06:49:11.004700Z

$HOME/.m2/repository

seancorfield 2021-03-25T06:49:26.005100Z

(same as macOS and effectively the same as Windows)

seancorfield 2021-03-25T06:49:39.005500Z

All Clojure dependency tools use the same location.

seancorfield 2021-03-25T06:50:40.006400Z

If you use sudo, I would expect it to use root’s ~/.m2 location (but… why on earth would you use sudo with this?)

zackteo 2021-03-25T07:07:28.008600Z

I mistakenly believed that I might need sudo permissions for ssh capabilities 😅 Am trying to use jepsen for testing for a distributed systems project

zackteo 2021-03-25T07:07:44.008900Z

Realised I don't have a jepsen nodes set up

zackteo 2021-03-25T07:10:40.010400Z

I realise is perhaps a bad habit, cause there have been many instances where I spent a lot time figuring out what is wrong with my commands, only to realise all i needed was sudo

Adie 2021-03-25T08:03:05.011200Z

Hi Can anybody suggest the best way to setup clojure project on intellij?

pavlosmelissinos 2021-03-25T08:03:49.011600Z

https://cursive-ide.com/ check #cursive as well

Adie 2021-03-25T08:03:50.011800Z

Also what is the best ide for clojure?

🔥 1
Adie 2021-03-26T08:04:34.067200Z

Is Cursive plugin free with intellij Ultimate @raspasov or Do I need to buy a cursive license separately?

raspasov 2021-03-26T08:12:07.067600Z

@aditi.mishra https://cursive-ide.com/buy.html

pavlosmelissinos 2021-03-26T08:21:39.068Z

the Non-Commercial license of cursive is free, regardless of you version of intellij

Adie 2021-03-26T08:31:00.068200Z

and which one should I go with?

pavlosmelissinos 2021-03-26T08:35:12.068400Z

You've read the linked page and you're still not sure?

Adie 2021-03-26T08:45:09.068600Z

I was wondering if there is any difference at the usage level for the two. Looks like its same for all the licences

👍 1
Adie 2021-03-26T08:51:11.068900Z

I have installed the cursive plugin in my intellij idea ultimate. Only after putting the license in intellij, it will start working. Right? After restarting IDEA, Cursive should be working out of the box. Follow the user guide to fine-tune appearance, keybindings, code style etc.

pavlosmelissinos 2021-03-26T08:51:44.069100Z

Correct

1
sb 2021-03-25T08:05:18.012700Z

From help menu, you could find all shortcuts

Adie 2021-03-25T08:06:34.014Z

Want to get rid of these highlights

Adie 2021-03-25T08:07:26.015Z

pavlosmelissinos 2021-03-25T08:07:40.015200Z

The best ide for <language> is the one you're most comfortable with. Which one do you already have experience with? Start with that and if for some reason at some point that's not enough and you want to switch to something else, do it then, not before. It's hard having to learn Clojure and a new editor workflow at the same time.

Adie 2021-03-25T08:08:37.016Z

Yeah. That makes sense. Thank you. I want to use Intellij

pavlosmelissinos 2021-03-25T08:09:46.016400Z

Yup, I'd say start with that then, it's a decent IDE and was my first experience with clojure as well. Have fun!

pavlosmelissinos 2021-03-25T08:12:18.016600Z

Might be the case that cursive can't "see" the clojure compiler but I'm not sure, it's been a while since I last used it. Better to ask over at #cursive I think.

raspasov 2021-03-25T08:22:54.017300Z

@aditi.mishra definitely checkout Cursive then, you won’t be disappointed. Been using it for years.

👍 2
motform 2021-03-25T10:17:34.017600Z

Does anyone have any recommendations of TCP clients to use with Clojure? I want to programatically communicate with a prepl over the wire. I'm assuming the answer is Aleph, but it feels like there is a lot of buy-in with manifold and byte-streams.

2021-03-25T10:20:14.018600Z

@love.lagerkvist Http kit? https://github.com/http-kit/http-kit

motform 2021-03-25T10:23:20.019200Z

Is it possible to use http-kit to do raw tcp communication? I reckoned it was limited to http requests. Networking is not my stronget suite, so forgive me if those terms are interchangable in this context.

Kenneth Gitere 2021-03-25T10:55:08.021100Z

Hi Clojurians. I'm not very familiar with libraries in cljs (or Clojure in general) but I noticed that most frontend frameworks are React inspired in some way. Are there any frameworks that work similar to Svelte?

John Preston 2021-03-25T11:19:39.023900Z

Hi all, I am trying to set up tracing in Datadog for a Clojure app which is packaged with Capsule, and I need to specify the packages whose methods I want to trace. Can someone please tell me how Clojure namespaces map on to Java packages? e.g. if I have ns's john.core , john.foo.core , ... will these each become their own package at run-time (since I am not using AOT)? Thank you 🙂

2021-03-25T11:25:39.024Z

No you can't. My bad, I read your request too quickly. 🙏

2021-03-25T11:27:46.024200Z

If you want to keep it simple as possible, you can use Java interop like that https://github.com/clojure-cookbook/clojure-cookbook/blob/master/05_network-io/5-09_tcp-client.asciidoc, otherwise, I think Aleph is the most likely solution.

💯 1
flowthing 2021-03-25T11:48:58.024500Z

I wrote this Gist some time ago about communicating with prepl using core.async: https://gist.github.com/eerohele/e06551b115c6a31d1280a115c4c2abb2

flowthing 2021-03-25T11:49:37.024700Z

But if you don't already have core.async as a dependency or don't want to add it, you could just use something like java.util.concurrent.LinkedBlockingQueue.

motform 2021-03-25T12:00:01.027400Z

Thanks, I'll check the interop example out!

simongray 2021-03-25T14:02:27.028200Z

Thomas Heller who makes Shadow-cljs is working on something like that: https://www.reddit.com/r/Clojure/comments/m2bvy1/shadowgrove_playground_sneak_preview/

👍 1
2021-03-25T15:59:05.028700Z

yeah, Socket would be my first go to if all I need is TCP itself

👍 1
Franco Gasperino 2021-03-25T16:53:39.030200Z

when considering an external map structure, is it best practice to convert all keys to keywords (assuming they're all strings) and internally leverage keywords for access?

Franco Gasperino 2021-03-25T16:59:06.030700Z

e.g. keywordize-keys on all external map structures

2021-03-25T17:04:47.032900Z

no

2021-03-25T17:06:31.033800Z

I think maybe you can make the argument for keywordizing when the maps have a closed known set of keys, but otherwise it is a waste

DoubleU 2021-03-25T17:11:10.035600Z

Hey everyone, I’m trying to figure out a way to enable a css class for xx number of seconds when a user clicks a button, for example, I have this:

[:div {:class "refresh-icon -animate"}]
but i only want to show the -animate class for xx number of seconds when a user clicks some button. In React, I would do something like this:
&lt;div className={`refresh-icon ${showAnimation ? '-animate' : ''}`}&gt;{props.icon}&lt;/div&gt;
and then have a method where I would toggle showAnimation true/false can someone lend a hand please? Thanks

dpsutton 2021-03-25T17:12:27.036100Z

(cond-&gt; "refresh-icon" show-animation? (str " -animate"))

Franco Gasperino 2021-03-25T17:12:50.036200Z

in this case, i have a known set of keys which i'm treating as a schema. I wish to walk an external structure and assert those keys are present and perform some additional validation on the values associated. The inbound map would likely arrive as string keys. So given your advice, i should treat my schema keys as strings and not keywords.

DoubleU 2021-03-25T17:16:18.036600Z

thanks @dpsutton, i’ll if i can make that work

Franco Gasperino 2021-03-25T17:17:39.038400Z

(def internal-schema #{:a :b})
(def external-content {:a 1 :b 2})

(remove #(contains? external-content %) internal-schema)
()

(def external-content {"a" 1 "b" 2})
(remove #(contains? external-content %) internal-schema)
(:b :a)

dpsutton 2021-03-25T17:17:41.038600Z

at my last job we had a nice utility function for combining class names (u/classes "refresh-icon" {"-animate" show-animation?}) that would take the map of classes and the booleans of whether to add them and combine them. you could implement a function that does this or just use the one-off cond-> style here. The implementation of the utility function would be some kind of accumulation followed by a string/join with a space

Franco Gasperino 2021-03-25T17:19:16.038700Z

external-data would be sourced from an input stream containing json maps.

DoubleU 2021-03-25T17:20:51.038900Z

Oh clever, i think the one off will be fine for now

DoubleU 2021-03-25T17:53:18.039200Z

@dpsutton, should my entire line look something like this: [:div {:class (cond-&gt; "refresh-icon" show-animation? (str " -animate"))}

dpsutton 2021-03-25T17:57:56.039400Z

your problem is you need to dynamically create a string. the context doesn't seem relevant. that expression should create the string you care about, provided you have a local var called show-animation?. Did it work?

DoubleU 2021-03-25T17:57:56.039600Z

actually that doesn’t look right, my compiler is yelling at me, it doesn’t like the show-animation property

DoubleU 2021-03-25T17:58:12.039800Z

in my function, I added: (def show-animation false)

dpsutton 2021-03-25T18:01:19.040Z

don't put defs inside of functions. use (let [show-animation? false] your-stuff-here)

cschep 2021-03-25T18:10:21.041Z

is there a simple way in clojure to say if not nil this else that e.g. (player :fantasy-team) ?? "No Team"

cschep 2021-03-25T18:11:10.041200Z

feel clunky to write out a whole if

walterl 2021-03-25T18:11:35.041300Z

(get player :fantasy-team "No Team")

walterl 2021-03-25T18:12:29.041500Z

Or (pun intended)... (or (:fantasy-team player) "No Team")

walterl 2021-03-25T18:12:53.041700Z

AFAIK the former is preferred

cschep 2021-03-25T18:12:57.041900Z

ohhhh nice

cschep 2021-03-25T18:13:02.042100Z

thanks!

cschep 2021-03-25T18:13:08.042300Z

didn’t know maps could have default values but of course

walterl 2021-03-25T18:14:07.042500Z

Not maps, but get 🙂

cschep 2021-03-25T18:15:12.042700Z

err yeah thanks 🙂

walterl 2021-03-25T18:15:49.042900Z

Oh wait... Maps do too!

walterl 2021-03-25T18:16:15.043100Z

({:foo "foo"} :missing :default) =&gt; :default

2021-03-25T18:16:55.043300Z

Keywords too

seancorfield 2021-03-25T18:23:07.043700Z

Because they do a get under the covers (essentially).

seancorfield 2021-03-25T18:24:26.043900Z

A hash map can be treated as a function that calls get on itself with the provided argument(s). A keyword or symbol can be treated as a function that calls get on its first argument, passing itself as the second argument to get, optionally passing the last argument (default) through.

seancorfield 2021-03-25T18:25:35.044200Z

It’s why when folks end up with a symbol (instead of an actual function) and do (f 1) or (f 1 2) they get nil instead of an exception.

2021-03-25T18:26:00.044500Z

the external structure is some serialized format - it has not types or implementation yet it's common practice to keywordize keys, but I've seen massive waste of effort in turning some external data into an internal "idiomatic" structure of the same shape, eg. turning "camelCase" into "kebab-case" etc. and implicit keywordizing can lead to the problem of the concretization of the serial format into program data being implicit, and then spread through the program maybe you want keywords maybe you don't, but definitely have an explicit step where the input-stream / string / whatever is turned into usable internal data

seancorfield 2021-03-25T18:26:27.044700Z

(having (f) or (f 1 2 3...) would give an arity error)

2021-03-25T18:27:13.044900Z

the bug where keywordizing arbitrary strings would use up the heap is gone, but keywordizing keys when you aren't converting to a specified internal format is still silly

2021-03-25T18:27:50.045100Z

I'd rather see (get input-data "someJSONKey") than (:someJSONKey input-data)

2021-03-25T18:30:49.045300Z

something to keep in mind is a map lookup with a default will only return the default if the key does not exist in the map, so if the key is in the map and associated with nil, you will get nil back

cschep 2021-03-25T18:31:28.045500Z

all very helpful, thanks everyone!

2021-03-25T18:44:16.045700Z

(f 1) will probably give you undeclared var exception. ('f 1) shouldn't

seancorfield 2021-03-25T18:46:08.045900Z

@delaguardo f was illustrative of a bound symbol: my comment was about passing in a symbol instead of a function value, into code that tried to call it. Sorry, that wasn’t clear.

DoubleU 2021-03-25T18:46:53.046100Z

yeah i read that somewhere and changed it to

(let  [show-animation false])
in my on-click I have:
:on-click (fn [] (show-animation true))
because i want to change it to true when clicked which should show/hide the -animate style here:
[:div {:class (cond-&gt; "tasks--toast-icon" show-animation? (str " -animate"))}

seancorfield 2021-03-25T18:46:56.046300Z

(that cropped up the other day in relation to someone trying to pass a configurator function into the Jetty adapter via Leiningen project.clj config — because project.clj is data, some.ns/my-cfg is a symbol instead of a function, and the Jetty adapter assumed it was given a function and just “called” the symbol… which “worked” insofar as not throwing an exception but just evaluated to nil because it was basically (f server))

NoahTheDuke 2021-03-25T19:33:29.047800Z

terminal/repl question: For some reason, when I type something into the repl and press "Enter", it deletes the prompt (pushing my input to the left edge of the screen). any ideas why or how to fix this?

2021-03-25T19:36:32.048500Z

It's an issue with some rlwrap versions

seancorfield 2021-03-25T19:36:56.048900Z

@nbtheduke I believe that’s a bug in an older ve… yeah, what @hiredman said.

dpsutton 2021-03-25T19:37:20.049600Z

cat ~/.inputrc
$if clojure
    set enable-bracketed-paste off
$endif

seancorfield 2021-03-25T19:37:21.049700Z

I’m on an old Mac and have an old rlwrap and it happens to me. I’ve just learned to live with it 🙂

2021-03-25T19:37:22.049800Z

There was some Q&A on line in the last 4 weeks or so I saw, but not sure where. http://ask.clojure.org maybe?

dpsutton 2021-03-25T19:37:37.050300Z

forgot where i found this snippet

2021-03-25T19:37:41.050500Z

With workaround and to track when rlwrap release fixes it

seancorfield 2021-03-25T19:37:50.050800Z

Ah, yes! I remember that now. And I think I added that workaround on one of my machines…

dpsutton 2021-03-25T19:39:12.051300Z

its quite annoying if you're creating a bug report and the prompt disappears and you have to manually add it back in

NoahTheDuke 2021-03-25T19:39:25.051600Z

that snippet fixes it, thank you!

NoahTheDuke 2021-03-25T19:40:07.052Z

thank you! that's great

2021-03-25T19:40:12.052200Z

maybe answered in my replies above

dpsutton 2021-03-25T19:43:46.052500Z

yes it did thanks! and i was able to remove the workaround after upgrading rlwrap so double thank you

seancorfield 2021-03-25T19:45:23.053300Z

I have that .inputrc file on my old Mac but it doesn’t fix it. I guess my rlwrap is too old?

seancorfield 2021-03-25T19:46:05.054100Z

(for multi-line pasting — if it’s just a single line, the prompt doesn’t disappear)

DoubleU 2021-03-25T22:45:24.059400Z

Hi Everyone, I think I’m pretty close to figuring out this issue, but I’m wondering why my show-animation property isn’t updating to true and I wanted to find out if the steps below look correct. I created a variable in my method (let [show-animation? (r/atom false)]... I have a -animate style that I want to show when show-animation is true

[:div {:class ["refresh-icon"
                       (when @show-animation? "-animate")]}
and I have an on-click method that sets show-animation to true when clicking:
:on-click (fn [] (reset! show-animation? true))} "Show Animation"]...
Nothing is happening when I click the Show Animation button. Is there something obvious that I’m missing here? Edit: might also be worth mentioning when I println show-animation I see #&lt;Atom: true&gt;

2021-03-25T23:28:12.061500Z

I don't use clojurescript, or do much javascript, but you are almost certainly running afoul of whatever is rending [:div ...] as html not knowing it needs to re-render when the atoms value changes

2021-03-25T23:29:07.062100Z

I think most js/cljs frameworks need to be told about those kind of dependencies in someway

dpsutton 2021-03-25T23:31:12.062700Z

one common bug is to put the let binding of the atom inside the render function, which sets the value of the r/atom to false on each render

dpsutton 2021-03-25T23:33:38.062800Z

(defn component [] (let [show? (r/atom false)] [:div {:classname (if show? "show" "hide") :on-click #(swap! show? not)}])) ;; vs (defn component [] (let [show? (r/atom false)] (fn [] [:div {:classname (if show? "show" "hide") :on-click #(swap! show? not)}])))

👆 1