Fork me on GitHub
#clojure
<
2022-08-14
>
pinkfrog03:08:12

I just know this is a valid invocation. 🫥

(defn fun
    [{:keys [a]}])
  (fun 3)

dpsutton04:08:35

fun destructures a map in its signature. you are calling it with an integer

dpsutton04:08:07

(get 3 :a) is nil

pinkfrog05:08:41

I see . I thought some interface is required to be implemented by the argument. Turns out not.

pinkfrog05:08:33

@U11BV7MTK I saw too many places in metabase

dpsutton05:08:36

Yes documention. Since the function is defined with partial and not a defn form it would not have arglist documentation automati

pinkfrog05:08:06

Are you using cider? Calva does not have the arglist for multimethod showing. Actually this probably is not a Calva problem, it is the cider-nrepl not showing it, but I am not using Cider so I am not sure how actually the Cider behaves.

dpsutton06:08:23

Cider should show that metadata. I’m not using cider though

dpsutton06:08:52

I suspect it's lsp not showing the metadata since it is set at runtime

escherize18:08:49

I use cider and I see the arg lists.

pinkfrog01:08:04

@U0ETXRFEW sounds like cider can do it.

pez06:08:19

Calva too, since cider-nrepl in this case provides the arglists,

pez06:08:15

Though, for some reason Calva loses track on the current argument when the lists are provided as lists. Providing them as vectors work. Very strange.

pinkfrog07:08:46

Cool. Must be something wrong on my side. Btw, how do you get the colorflu one, two ?

pez07:08:02

The colorful current arg markup is probably something that the theme needs to implement. I'm not quite sure though. I'm using GitHub Dark default.

pez07:08:43

Maybe you forgot to evaluate the defmulti after adding the arglists, @UGC0NEP4Y?

pinkfrog07:08:24

Right, possibly the case. I am getting it now! @U0ETXRFEW Thanks as always!

🙏 1
👍 1
vemv17:08:51

what could be happening? I've done this sort of thing before

java -jar my-uberjar-standalone.jar clojure.main -m my.main

{:clojure.main/message
 "Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.java:-2).\nclojure.main, (No such file or directory)\n",
 :clojure.main/triage
 {:clojure.error/class java.io.FileNotFoundException,
  :clojure.error/line -2,
  :clojure.error/cause "clojure.main, (No such file or directory)",
  :clojure.error/symbol java.io.FileInputStream/open0,
  :clojure.error/source "FileInputStream.java",
  :clojure.error/phase :execution},
my/main.clj (actual name redacted) does exist in my uberjar (I'm intentionally skipping AOT, and indeed I get a .clj file and no .class files for the project itself)

seancorfield17:08:13

Because you're using -jar, it is running clojure.main automcatically, so the rest of your command-line is being passed as arguments to clojure.main/-main as strings: "clojure.main", "-m", "my.main"

seancorfield17:08:32

So it looks for a Clojure script to run called clojure.main and cannot find that.

seancorfield17:08:44

You want -cp instead of -jar @U45T93RA6

vemv17:08:00

java -jar my-standalone.jar -m my.main worked as well. I have to use -jar for devops reasons. Thanks much for the hint! :)

vemv17:08:16

I wonder if the implicit setting of clojure.main as a :main from Leiningen's side was a reasonable choice (maybe you have to set something?) I had never encountered this before as I'm more used to -cp

Alex Miller (Clojure team)17:08:28

You only have to set a main if you want to use it with -jar

👍 1
seancorfield17:08:00

-jar runs -main from whatever class is specified in the MANIFEST.MF file in the JAR for Main-Class: which I think most Clojure tooling defaults to clojure.main if you don't specify a different class (namespace).

thanks3 1
Alex Miller (Clojure team)18:08:35

It used to be the clojure jar itself set that and tools that made uberjars might pull it over through that. But now you need spec so that won't work anymore

👀 1
seancorfield18:08:41

@U064X3EF3 Can you clarify what "won't work anymore"?

Alex Miller (Clojure team)18:08:02

Using only the Clojure jar with -jar

seancorfield18:08:17

Which we're not talking about in this thread 🙂

Alex Miller (Clojure team)18:08:45

I know, but we used to set it, and then during uber some tools would pull it over into the uber manifest, which could be how / why lein did this now

seancorfield18:08:00

Ah, wow, that seems fragile...

rmxm19:08:49

does anyone have join-paths snippet that would be reasonable for most cases of paths, I know the problem is quite complex and difficult to converge in generic way, still looking for good candidates to cover 95% 🙂

p-himik19:08:34

You mean file system paths? If so, might be suitable. Alternatively, you can use java.nio.file.Paths/get, although given that it's a variadic function, the interop isn't as nice.

rmxm19:08:48

I mean most paths, including urls... but without understanding the nature of urls, rather looking for common separators

rmxm19:08:10

to not really care if its file path, or s3 path, or http path etc

skylize20:08:22

The / part is pretty universal in most things we commonly refer to as "path" (Even Windows reading a file path will typically read / just fine, even if it writes back out a \ in its place.) Beyond that you need to know the rules of your protocol. If by "path", you really mean URI (i.e an absolute local "file" path would look like ), then https://github.com/lambdaisland/uri could be helpful. The API does include join, which follows RFC 3986 rules for path merging. I've been pretty deep in that code and can verify it follows RFC 3986 spec quite closely. The only major flaw I've managed to find so far in regards to said spec is he encodes spaces with + instead of %20. That comes from the HTML Forms spec, and IMHO should be outside the scope of a lib that makes no other reference to HTML, and only even mentions HTTP in usage examples.

Drew Verlee19:08:12

If a web handler is part of a https://github.com/stuartsierra / https://github.com/stuartsierra/component is it possible to reload it outside the component lifecycle? It would be nice to speed up the reload by having clojure tools namespace repl do the work, which on my tiny projects works given you hand the handler ref and not the value e.g do this: #'handler or this (fn [x] (handler x) not this handler .But on a larger project, once that handler is part of component lifecycle it doesn't seem to get affected by a ns refresh.

vemv09:08:01

what web 'framework' are you using?

jaide19:08:39

Is cljfmt still the most common clojure formatter or is there a new hotness?

lread20:08:44

Cljfmt is popular but there is also https://github.com/kkinnear/zprint which offer lots of fine controls and https://github.com/greglook/cljstyle (which is a rewrite of cljfmt).

jaide20:08:23

Thanks! Seems like cljstyle has not been updated in a while though

jaide21:08:22

By chance is there a good tool for formatting stdin to stdout? Maybe https://github.com/borkdude/jet?

lread22:08:40

jet is more for edn data transforms/searches, but it does have a --pretty option for pretty printing edn.

jaide22:08:55

Ah that makes sense, thanks

👍 1
James Amberger20:08:45

Anyone aware of any resources/advice to ease porting a Django app?

jaide20:08:11

Out of curiosity what stack are you porting it to?

James Amberger20:08:55

I’m a fairly recent convert to Clojure{,Script}; I imagine this would just be a Ring app. It has to talk to a local mysql database and it has to drop mail in the local mail queue too

p-himik20:08:24

Have done it around 5 years ago. Don't think there's anything that makes it easier, but the rewrite itself was pretty straightforward even though I used to use a significant chunk of Django functionality at the time, along with the Rest Framework.

James Amberger20:08:44

I would just call it a rewrite and not a port and get started, but it’s a requirement that I not force the users to recreate their accounts

p-himik20:08:19

I had to do the same. It ended up in me extending the right multimethods of buddy so it can parse and create digests of the right format. Alternatively, you can just add a DB migration that simply converts the digests (assuming you're using the most trivial user account storage - password digest in the DB).

jaide20:08:54

That should be doable. Would recommend something like integrant, Component, or similar tool to manage stateful resources like the mysql db connection

James Amberger20:08:06

@U2FRKM4TW I am, and when I first picked up clojure I did fool around with buddy and arrive at some functions that would serve. Maybe that’s just the thing to do. @U8WFYMFRU Will investigate these, thanks!

James Amberger20:08:46

I guess I should just jump in. From where I now stand, just upgrading to Django 4.0 and python3 doesn’t seem like fun.

💯 1