beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
2020-11-13T01:10:57.150400Z

@pmonks Hum, not that I know, you can make one yourself. That said, you could also consider using metadata to mark a namespace as pure or not, same on your functions.

👍 1
2020-11-13T08:07:51.158Z

Ya, I have no idea what you want this for, so you know best. Just saying it's an option as well.

👍 1
Joe 2020-11-13T01:16:54.150900Z

Hm, that might be a disqualification for Heroku. Though I see the do offer separate DBs, including Kafka

st3fan 2020-11-13T01:48:34.152200Z

Hmm is there no if-let that takes multiple bindings?

alexmiller 2020-11-13T02:04:39.152400Z

no

alexmiller 2020-11-13T02:05:09.152900Z

you can destructure though and let multiple values out of that (while if-ing on the collection)

alexmiller 2020-11-13T02:05:34.153400Z

(if-let [{:keys [foo bar]} some-maybe-nil-map] ... )

alexmiller 2020-11-13T02:06:04.154Z

the if is based on whether some-maybe-nil-map is nil

st3fan 2020-11-13T02:07:02.154800Z

My code would be something like when-let [foo (get-foo) bar (get-bar foo)] …

2020-11-13T02:19:11.155200Z

You may just want some->

2020-11-13T02:37:28.155300Z

Yeah that doesn’t let me differentiate at-a-glance in the filesystem (my main intent here is to communicate to humans, not to the computer).

2020-11-13T02:47:18.155500Z

Hum... I guess it depends where the human is looking

2020-11-13T02:47:38.155700Z

But (defn ^:pure foo [] ...) is pretty visible to a human

2020-11-13T02:51:16.155900Z

Same for: (ns ^:pure my-ns)

xlfe 2020-11-13T04:57:57.156900Z

@st3fan I've been using https://github.com/ptaoussanis/encore which includes when-let plus other -let constructs for multiple bindings

2020-11-13T05:05:38.157100Z

Yep those could work, though neither qualify as “at a glance in the filesystem” mechanisms.

xlfe 2020-11-13T05:08:22.157400Z

👋 hi all. Just wanted to introduce myself. I'm the co-founder of a startup in Canberra Australia that's building enterprise software on a clojure/script stack. key parts of our stack include datomic, keechma-next, sente and shadow-cljs. We're just starting out but over time I'd like to give back to the clojure community in various ways.

❤️ 2
👋 5
pithyless 2020-11-13T08:21:13.161800Z

@st3fan https://github.com/Engelberg/better-cond exports a version of if-let and when-let that checks multiple bindings; I don't use them myself, but I do use the better/cond macro that is useful when writing code that starts leaning right towards multiple indent levels.

1
Daniel Östling 2020-11-13T11:04:05.167300Z

Is there an idiomatic way to merge vector of maps so that some values for some keys are aggregated, but others are not? Something like

[{:a "1", :b :some-keyword, :c "x"} {:a "1", :b :some-keyword, :c "y"}]

would be transformed into

{:a "1", :b :some-keyword, :c ["x", "y"]}
I’ve been playing around a bit with merge-with, but I can’t get it quite right.

Ben Sless 2020-11-13T11:33:53.167500Z

I wrote this for a colleague some weeks ago, you might find it useful https://gist.github.com/bsless/e76a6537907ad4eecd69dcb321318b95

kongeor 2020-11-13T11:45:07.167700Z

it's not that pretty but it works:

kongeor 2020-11-13T11:45:09.167900Z

(def data [{:a "1", :b :some-keyword, :c "x"} {:a "1", :b :some-keyword, :c "y"} {:c "z"}])

(apply merge-with (fn [m v]
                    (if (= m v)
                      m
                      (if (vector? m)
                        (conj m v)
                        [m v]))) data)

kongeor 2020-11-13T11:45:49.168100Z

check the source code, it should be relatively simple to follow the code: https://github.com/clojure/clojure/blob/clojure-1.10.1/src/clj/clojure/core.clj#L3051

Daniel Östling 2020-11-13T11:46:36.168400Z

Thanks, I appreciate it 🙂

kongeor 2020-11-13T11:47:44.168600Z

cheers 🙂

Daniel Östling 2020-11-13T11:48:46.168800Z

And thanks @ben.sless, that also looks useful 🙂

kongeor 2020-11-13T11:49:30.169Z

sorry, there is a bug:

kongeor 2020-11-13T11:49:32.169200Z

(merge-with (fn [m v]
              (if (vector? m)
                (conj m v)
                [m v])) {:a 1 :b 5} {:a 1 :b 3})

kongeor 2020-11-13T11:49:41.169400Z

this will produce => {:a [1 1], :b [5 3]

kongeor 2020-11-13T11:49:45.169600Z

which I think it's what you want

Ben Sless 2020-11-13T11:54:56.169800Z

my foldmaps might even be overkill for your task, because you have only one "index". You can ofc just rip the indexing part out of it

Ben Sless 2020-11-13T11:56:27.170Z

you can just (reduce (map-combiner {,,}) ms)

Daniel Östling 2020-11-13T12:03:08.170400Z

Yeah, I’ll take a closer look. I like to understand code I use 🙂

Daniel Östling 2020-11-13T12:03:49.170600Z

Thanks guys 🙂

🙂 1
Ben Sless 2020-11-13T12:36:40.171300Z

godspeed 🙂

oly 2020-11-13T12:42:39.172100Z

anyone used googles artifact repository with clojure jars managed to upload but cant convince deps to checkout the jar

st3fan 2020-11-13T12:56:49.172200Z

Thank you I’ll take a look at that one

Jim Newton 2020-11-13T13:01:31.174200Z

help calling java method. I'm looking at the source code for isa? and I see the line:

(and (class? parent) (class? child)
            (. ^Class parent isAssignableFrom child))
How can I call the isAssignableFrom method from the repl? Do I need to qualify it with some java.this.and.that/isAssignableFrom, or do I need to require something into my repl? Here's the error I'm getting.
(. Number isAssignableFrom Long)
Syntax error (IllegalArgumentException) compiling . at (clojure-rte:localhost:51477(clj)*:318394:23).
No matching method isAssignableFrom found taking 1 args for class java.lang.Number

st3fan 2020-11-13T13:04:03.174400Z

Oh no I need a YAML library

pyry 2020-11-13T13:16:21.174500Z

(.isAssignableFrom Number Long)

✔️ 1
pyry 2020-11-13T13:24:42.174700Z

Sorry, realized that I wasn't actually answering your question, but the above should work nonetheless.

😀 1
st3fan 2020-11-13T13:29:15.175500Z

What is an idiomatic way to translate something like this to Clojure:

if (foo && bar) {
   return;
}

if (something == false) {
   return;
}

if (something_else) {
   return
}

dosomething()

st3fan 2020-11-13T13:29:46.176100Z

I’m trying to avoid inverting those conditions and creating a huge indented if pyramid

st3fan 2020-11-13T13:30:48.176600Z

factor it out in a function and just use or ?

st3fan 2020-11-13T13:32:54.177300Z

inverting expressions makes the decision logic hard to read

alexmiller 2020-11-13T13:36:35.177500Z

cond ?

alexmiller 2020-11-13T13:37:09.177900Z

I mean, this is already weird because it's a void method and those don't exist in Clojure

alexmiller 2020-11-13T13:38:15.178900Z

but:

(cond
  (and foo bar) nil
  (false? something) nil
  (something_else) nil
  :else (dosomething))

alexmiller 2020-11-13T13:38:21.179100Z

is effectively the same

alexmiller 2020-11-13T13:39:14.179900Z

maybe at that point I'd do:

(when-not (or (and foo bar)
              (false? something)
              (something_else))
  (dosomething))

oly 2020-11-13T14:21:50.182700Z

from what I can figure out i need to use a wagon in deps.edn but not finding anything online

oly 2020-11-13T14:24:07.185300Z

{:mvn/repos
 {"artifactregistry" {:url "<artifact-registry://europe-west2-maven.pkg.dev/production/test-maven>"}}}
I have added the above to deps.edn but seems it does not understand artifact-registry from what i can work out it needs to launch something to add that protocol format, not finding any details on how to go about that how ever 😞

Gleb Posobin 2020-11-13T14:24:57.185600Z

I have read a bunch of stuff about spec, but still don't understand when I am supposed to use it. Should I spec every function definition? What about the performance costs of that? Also, spec suggests that the keywords I use in hash-maps should be namespaced, is that a standard practice? I haven't seen that recommendation anywhere else I think, besides fulcro docs maybe.

2020-11-13T14:34:16.185800Z

I believe it is fairly common for those who use spec to use it in production only to check inputs at the boundaries of major subsystems, e.g. for requests from outside of one piece of software, or perhaps sometimes between major subsystems. The run-time cost can be mitigated by being selective. For test time, it can be worth the extra checking time to enable checking at many more places. For testing individual functions or groups of your functions, generative testing, e.g. with test.check can help provide good test coverage at test time.

2020-11-13T14:35:44.187200Z

Is this one of the articles you read on spec? It is written by a long time Clojure developer who has used spec in their production Clojure code for several years now.

oly 2020-11-13T14:35:50.187800Z

seems mixing lein and deps.edn using this plugin https://github.com/lurodrigo/lein-artifact-registry/ and then using lein-tools-deps to read the deps.eddn file seems the dependencies are merged would be nicer to do this all in deps file if its possible ?

Gleb Posobin 2020-11-13T14:36:13.188Z

No, I don't think I have read that one, thank you!

Gleb Posobin 2020-11-13T14:37:27.188200Z

So I should define some of the specs inside test namespaces then, if I want them to run during test time?

2020-11-13T14:38:31.188400Z

I believe some people create completely separate namespaces for spec definition, so that they can be loaded only when desired. By doing that, they can be loaded at test time, true, but they can also be loaded at production time without loading in all of the test code.

Gleb Posobin 2020-11-13T14:39:05.188600Z

I see, makes sense, thank you. I'll read the post and ask more questions if I have any.

2020-11-13T14:39:37.188900Z

Probably the only reason the author didn't answer your question before I did is because it is very early Pacific time right now 🙂

😄 1
alexmiller 2020-11-13T14:44:17.189300Z

clj does not have support for custom wagons/transporters right now

alexmiller 2020-11-13T14:44:37.189500Z

filing a request at https://ask.clojure.org would be a great place to make a votable thing that we can track

alexmiller 2020-11-13T14:45:29.189900Z

the underlying tools.deps lib does support custom procurers but does not specifically support custom transporters or wagons, but that is possible to add

alexmiller 2020-11-13T14:46:33.190200Z

see my thread above

oly 2020-11-13T15:29:44.190300Z

okay thanks for the info, i was about to ask on reddit 🙂 I will post on ask.clojure as suggested

oly 2020-11-13T15:31:07.190500Z

although ask only seems to let you register with github 😞

oly 2020-11-13T15:32:11.190700Z

thanks anyway, i will go back to using lein for now

oly 2020-11-13T15:32:39.190900Z

perhaps i will post on reddit as well just so there is some history 🙂

Louis Kottmann 2020-11-13T15:56:08.192500Z

do I get it right that clojure.core.async/go and future have the exact same purpose, except for their respective thread/pool subtelties?

Louis Kottmann 2020-11-13T15:56:26.192900Z

Louis Kottmann 2020-11-13T15:57:09.193800Z

and then, considering the error handling overhead that comes with future, I should use go if I don't care about threading boundaries?

alexmiller 2020-11-13T15:58:52.194800Z

I'd say they have entirely different purposes actually but if you're not doing any async ops, I'd use future

alexmiller 2020-11-13T16:00:06.194900Z

well posting there will cause nothing to change if that is your goal

Louis Kottmann 2020-11-13T16:00:25.195300Z

what do you mean, "not doing any aync ops"?

alexmiller 2020-11-13T16:00:31.195500Z

http://ask.clojure.org is where we collect and determine the priority of requests

alexmiller 2020-11-13T16:01:02.196600Z

parking ops like >! <! etc

Louis Kottmann 2020-11-13T16:01:11.196800Z

my actual current project uses futures, but I never dereference them (their purpose is network side-effects)

alexmiller 2020-11-13T16:01:28.197300Z

you should not do blocking io operations in go blocks

Louis Kottmann 2020-11-13T16:01:38.197700Z

and I'm really torn between keeping them and using core.async

alexmiller 2020-11-13T16:01:39.197800Z

as it is a fixed size pool and you can lock it up that way

alexmiller 2020-11-13T16:02:09.198200Z

it does not seem like you have a use case that matches core.async afaict

Louis Kottmann 2020-11-13T16:02:21.198500Z

I see

Louis Kottmann 2020-11-13T16:02:37.198900Z

and using go blocks with futures inside for the IO parts, would be overkill?

Louis Kottmann 2020-11-13T16:04:26.199900Z

I guess I really don't like the errors popping in places totally different from the actual crash place (I use try/catches with every futures), and naively believe that go blocks would somehow solve the problem

alexmiller 2020-11-13T16:05:06.200500Z

yeah, it would not help you with that

alexmiller 2020-11-13T16:05:28.200900Z

it does not seem like core.async solves any problem you have and likely introduces new ones :)

Louis Kottmann 2020-11-13T16:05:38.201100Z

😄

Louis Kottmann 2020-11-13T16:06:08.201400Z

ok let's avoid that pitfall then, thank you!

oly 2020-11-13T16:07:14.201500Z

how come it only has github sign up seems flawed if its the main way to track stuff

oly 2020-11-13T16:07:45.201700Z

will have another look perhaps i missed sign up button

alexmiller 2020-11-13T16:10:08.201900Z

it is github only right now

alexmiller 2020-11-13T16:10:44.202100Z

most devs have a github acct so that has not generally been an impediment so far. if you don't have one, I can file a request for you there

oly 2020-11-13T16:22:10.202300Z

that would be very helpful, I am also a bit suspect of the legitimacy of that site as it has various issues or perhaps its just very new

oly 2020-11-13T16:23:10.202500Z

not a site I have come across in the clojure eco system previously anyway

alexmiller 2020-11-13T16:23:32.202700Z

github?

oly 2020-11-13T16:23:48.202900Z

posting on reddit for posterity anyway as i will probably need the work around again

oly 2020-11-13T16:23:56.203100Z

no ask.clojure

alexmiller 2020-11-13T16:24:00.203300Z

https://ask.clojure.org is the official clojure Q&A site run by the core team, of which I am a member. I run it.

alexmiller 2020-11-13T16:24:18.203600Z

I'm also the primary dev on tools.deps and clj

oly 2020-11-13T16:24:42.203800Z

oh I did not knwo that

oly 2020-11-13T16:24:46.204Z

oly 2020-11-13T16:25:03.204400Z

is it supposed to look like that on a desktop ?

oly 2020-11-13T16:25:44.204600Z

feels like a mobile version and the x is mis aligned

alexmiller 2020-11-13T16:26:13.204800Z

that does look like the mobile layout - but it's a responsive layout so looks different as you widen it

oly 2020-11-13T16:28:24.205Z

I get column if i widen it and a categories box, not try to offend just thought i would point out if there is an issue

oly 2020-11-13T16:32:05.205200Z

good work on tools.deps anyway I actually really like it as a build tool for managing my projects

Roger Amorin Vieira 2020-11-13T18:43:01.208200Z

Hi, I dont know if is a bug, but last week, this work like that:

&gt; (format "%.3f" 2.0)
"2.000"
Now the same thing is giving to me:
&gt; (format "%.3f" 2.0)
"2,000"

2020-11-13T18:47:12.208800Z

@contato509 that looks like something that would be controlled by the LOCALE environment variable

2020-11-13T18:49:23.209500Z

oops - not LOCALE itself, but the locale system, that uses LANG, LANGUAGE, LC_CTYPE, LC_NUMERIC etc. (on linux at least)

Roger Amorin Vieira 2020-11-13T18:56:52.210100Z

Was that thanks

🍻 1