Fork me on GitHub
#clojure
<
2023-05-19
>
diego.videco00:05:19

Hello everyone. Why does this return 4? (apply (symbol "clojure.core" "+") [2 4])

seancorfield00:05:57

Because what you have is ('some-symbol 2 4) which is the same as (get 'some-symbol 2 4) (get 2 'some-symbol 4) and that's the not-exists arity so (get 'some-symbol 2) (get 2 'some-symbol) would return nil, and (get 'some-symbol 2 4) (get 2 'some-symbol 4) will return 4. [Thanks to @U7RJTCH6J for the correction later in this thread!]

👍 1
seancorfield00:05:11

A symbol != its value.

seancorfield00:05:57

(apply (resolve (symbol "clojure.core" "+")) [2 4]) is what you want

seancorfield00:05:27

That resolves the symbol 'clojure.core/+ to the value it is bound to, the function clojure.core/+

seancorfield00:05:14

(and if you're new to Clojure, this is a good question for #C053AK3F9 where folks are generally a lot more patient than in #C03S1KBA2 🙂 )

hiredman00:05:56

Symbols don't actually have values, they are just sort of loose identifiers, they will map to different values depending what you look them up in

diego.videco00:05:30

Thanks, not new to clojure, but trying to overload the plus function in macroland, and got confused about what was happening

seancorfield00:05:01

(I edited my comment to say "the value it is bound to" instead of "its value" -- if you resolve a symbol that doesn't have a root binding to a value, you get nil)

seancorfield00:05:20

Since we're being more pedantic 🙂

phronmophobic00:05:35

> Because what you have is ('some-symbol 2 4) which is the same as (get 'some-symbol 2 4) While we're being pedantic, ('some-symbol 2 4) is actually the same (get 2 'some-symbol 4)

seancorfield00:05:00

Thank you for catching that... yes!

seancorfield00:05:14

(edited original with correction and attribution)

😄 1
vemv05:05:13

TIL about invoking symbols :)

diego.videco14:05:46

ditto, very interesting, actually

Michael Gardner18:05:28

out of curiosity, has anyone here ever intentionally taken advantage of symbols implementing IFn? I don't think I've ever done it, or even seen it

Matti Uusitalo06:05:37

Handy tip for VisualVM users. It is sometimes difficult to tell which of these is my repl. Don't fret, write

(.pid (java.lang.ProcessHandle/current))
=> 735515
and have a good day simple_smile

Drew Verlee06:05:09

and if you use cider with emacs, their is a command to take you to the repl for the buffer your are currently in.

1
Ben Sless07:05:24

I got lazy and wrote something to launch visual vm from inside the java process 🙃

😎 4
jpmonettas11:05:48

for this I always add to my deps.edn (as soon I create it) a :jvm-opts ["-Dproject-name=MyFancyProject"] and then I can see it in VisualVm on the first tab

🎉 5
jmckitrick11:05:55

Is there an open source code coverage tool that doesn’t require lein like cloverage does? All I see are cloverage and a commercial option.

javahippie11:05:54

I’m pretty sure you can use cloverage from kaocha Edit: As @U04V4KLKC already mentioned and linked 🙂

🍻 1
Ben Sless12:05:54

You can run Cloverage with deps, too

Ben Sless12:05:05

you need to run cloverage.coverage and pass the args as opts map, it works just not most documented

Ben Sless12:05:30

clj -Sdeps '{:deps {cloverage {:mvn/version "RELEASE"}}}' -m cloverage.coverage *args-to-coverage*

Sam Ritchie12:05:02

Here’s my GitHub action for deps cloverage

jmckitrick13:05:01

That’s excellent. Very helpful

jmckitrick13:05:41

I’m surprised there aren’t any articles out there on this, but there are plenty for the lein approach from years ago.

Sam Ritchie13:05:25

Yeah, I find coverage to be really helpful, especially with GitHub’s highlighting of covered and not-covered lines

🔥 1
vemv19:05:37

What's the commercial option @U061KMSM7?

jmckitrick19:05:31

Maybe? I just discovered it today

vemv19:05:05

I wouldn't be surprised if it's just a wrapper for prettier reports / GH integration

javahippie19:05:15

I think they write about uploading coverage reports after creating them with cloverage. Seems to be dependent on cloverage or similar tools, rather than a replacement?