This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-13
Channels
- # aleph (16)
- # announcements (8)
- # aws (5)
- # babashka (54)
- # beginners (48)
- # calva (7)
- # cider (7)
- # clojure (209)
- # clojure-brasil (4)
- # clojure-europe (20)
- # clojure-italy (12)
- # clojure-nl (21)
- # clojure-uk (69)
- # clojurescript (24)
- # cursive (11)
- # datascript (7)
- # datomic (47)
- # emacs (14)
- # graphql (20)
- # hoplon (25)
- # jobs (1)
- # kaocha (1)
- # leiningen (14)
- # meander (7)
- # off-topic (44)
- # other-languages (1)
- # pathom (20)
- # re-frame (2)
- # reagent (51)
- # reitit (3)
- # remote-jobs (1)
- # shadow-cljs (46)
- # spacemacs (5)
- # sql (65)
- # tools-deps (86)
- # vim (11)
Does this definition make sense? Trying to make a wrapper similar to priority-map-keyfn
without falling into pitfalls with custom comparators
(defn sorted-set-keyfn
[keyfn & keys]
(apply sorted-set-by
(fn [a b]
(let [c (compare (keyfn a) (keyfn b))]
(if (zero? c)
;; break the tie consistently
(compare (hash a) (hash b))
c)))
keys))
sorted-set
and sorted-map
require total ordering because the comparator is also used for equality. hash
can't be used to break ties because of collisions.
I don't know if there's any practical reason why partial ordering could not be supported though
huh, that's interesting - I had assumed hash collisions would be much harder to come by
Regarding this:
https://clojure.org/guides/dev_startup_time
I recently tried using clj-kondo metadata to find the subtree’s of ns dependencies that are referenced by my project, but I get weird errors when running with the classes directory on my cp.
Stuff like ClassNotFoundException’s.
One thing to note: the project uses ig/load-namespaces
I don't know what that is
if you are partially compiling things and missing things you depend on, it's possible to get into bad scenarios. what happens if you do what's in the guide?
I can’t literally do what is in the guide; because the app uses ig/load-namespaces
; essentially the require tree is built dynamically by wiring in integrant config… esssentially stuart sierra’s dependency.
I’m not suggesting it is a herring; just that it and also perhaps the presence of tools.namespaces.repl/clear etc might be 🙂
load-namespaces
just ends up calling require
— same as ns
macro ends up calling require
true — it’s really the use of integrant.repl/reset
which causes me concern; rather than load-namespaces.
as that uses clojure.tools.namespace.repl/refresh
though I suspect it’s probably me messing up in my suggestions of namespaces to compile
@alexmiller Yeah ok it makes total sense that compile
assumes all transitive requires are also compiled. It’s most likely in my manual pass over the first results that I messed something up regarding transitive namespaces…
I had to for example remove some shadow-cljs npm requires; and also some cljs namespaces etc by hand; as it’s a mixed clj/cljs project.
It remembers me of an old https://groups.google.com/d/msg/clojure/NtQ9BJXbziA/AlONiMe9I0AJ discussion related to calling lein uberjar
(which adds compiled classes to the classpath) and then starting a REPL. Same class not found error and same relationship with having a component system in place. Never spent time to find the root cause, but now I always lein clean
after uberjarring.
I might be misunderstanding the issue, but I think these problems are caused by :aot
poluting other profiles.
I always prevented that with: https://github.com/technomancy/leiningen/blob/0455879f9a42629205e9cedb4d61f13054a5e1d7/sample.project.clj#L313-L317
No idea why lein never made this a default option tbh; I’ve always set it.
Woot!!!
Random ClassNotFoundException
was the exact reason I stopped using AOT for third-party libraries.
there is a lot of irrational fear around aot
Yeah I’ve always AOT’d apps, never really had any issues with it; that weren’t issues worth fixing anyway… e.g. side effects happening at compile/load time.
Integrant with dynamic namespaces/components makes it somewhat more difficult though — I’ve been wanting to resolve that for a while.
One thing the startup time link above doesn’t discuss is the pitfalls of doing it… e.g. presumably an app that downgraded a dependency to a prior version might have some problems
"Periodically, you will need to re-compile to account for new dependencies or changing code."
> AOT-compilation: Reloading code does not work in the presence of AOT-compiled namespaces. If you are using AOT-compilation in your project, make sure it is disabled and you have deleted any AOT-compiled .class files before starting a REPL development session. (In Leiningen, run lein clean.) Another example of a potential gotcha would be the above, though is the statement from https://github.com/clojure/tools.namespace/ even accurate though? I suspect it’s more nuanced than it lets on. i.e. presumably reloading will work in the presence of AOT-compiled namespaces; so long as the namespace that is being reloaded isn’t itself AOT-compiled? Is that right?!
is there a way to use namespace aliases to creating a record that is defined in another ns?
(ns app.worker)
(defrecord WorkerA [x] ...)
(pr-str (map->WorkerA {:x 1})) ;; => #app.worker.WorkerA{:x 1}
(ns app.other
(:require [app.worker :as w]))
#app.worker.WorkerA{:x 1} ;; works
#::w.WorkerA{:x 1} ;; doesn't work
you should really prefer using the constructor functions, which are normal functions and can be accessed via aliasing in the same way as any other functions
so here (w/map->WorkerA {:x 1})
would work fine
the #app.worker.WorkerA is a syntax for a Java class name constructor and Java class names have nothing to do with namespace aliasing
Definitely I've experienced AOT issues. AOT on your app is fine, uberjar style. But for libraries it's caused us issues in the past for sure
So what happens is you end up if dependency A uses B v1, and you depend directly on A and B v2. Then the AOT jar of A will actually contain the compiled classes of B v1
that does not seem right. by what process would that happen?
oh, I see
that seems like a bad process
not blaming you or anything
Ya, it is. What I did at work was we now have a custom jarring. So it'll filter through the classes-dir and select only classes of the package to Jar.
> That happens just if you compile A
Would the same happen if you run compile
with the same classpath that your app has?
The issue is, libraries publishing their Jars should not be AOT compiled, or if they are, should be very careful about what compiled classes they put in the Jar they vend
Hmm. Still at a loss then for why I was seeing ClassNotFoundException
from time to time when I was trying to compile the whole all.
If it's started where the classpath to the JVM doesn't point to all the needed dependencies this would happen
If you expect to use a generated class from gen-class for example, the classpath post compile must now include the compiled classes
But Clojure requires shouldn't be broken, even if they don't find the classes they fallback on the source
Well, yeah, I think the only difference was the "classes"
dir. Apart from that, the classpath was exactly the same.
Most of the time, it wasn't able to find manifold.deferred.IDeferred
which is a definterface
.
I’m making a form to upload a file. Simple stuff, only a field for a name, and a field for uploading. I already have some code in place to do this:
[:input {:type "file" :name "uploaded-file" :required ""
:accept ".xls, .xlsx, .ods, .csv, .tsv, .pages,
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,
application/vnd.ms-excel, text/csv,
application/vnd.oasis.opendocument.spreadsheet"}]
but if someone uploads a file through an android phone, they can still upload e.g. a pdf. Am I doing something wrong in that accept
attribute? If not, is there a way to do it server-side without adding cljs to my project?I think it can also be really finicky to find the correct combination of attributes for different browser and OS as well
But you will be able say, after the user picks a wrong file extension in the file picker, to do a quick client side validation before the file is uploaded (I think)
Otherwise you can do the same on the server side, though that means the file has to be fully transferred and all that
It can probably help you at this point to Google for HTML file accept or like how to restrict file selection of input file, etc.
And then when you depend on A, you get the classes of B as well. And if A depends on a different B, and because B is a source lib, and Clojure load favours classes over sources you will get the version of B defined by A
yeah, that seems like a problematic way to do aot, but I see how you get there
aot'ing from an app namespace makes you dependent on the classpath, which has already been resolved with version selection (only B v2 is available)
seems like if you are running all your compile's in that classpath context, same would be true right?
what tooling were you using for this or was it something custom?
but the classpath will not resolve to B v1 here
And Clojure Load will see that each namespace on B v2 (whose Jar only has sources) also have a .class on the classpath coming from A's Jar
maybe I was misunderstanding what you were talking about then. are you talking about publishing aot'ed library artifacts? or a process for aot'ing an app?
ah, don't do that
and if you do, they should only include that lib's classes
Yeah this is with custom tooling. But I remember looking what lein does and it seemed it would suffer the same faith
yeah, it is very easy to do it wrong (and it takes away choices from a downstream app builder)
compiled classes are inherently dependent on some version of the clojure compiler
if the lib compiles, the app doesn't have the opportunity to pick that
sorry I misunderstood :)
No worries, honestly it hurts my brain everytime I try and rethink about this issue. Dependencies are so hard
For us, we had a case of a dependency doing AOT because it also gen-classes itself so it can be consumed by Java and Clojure
yeah, that's hard
a couple of the contrib libs actually publish both source and aot versions (the latter under aot classifier)
well, actually clojure itself too has a "slim" version that is source-only
I did face this issue with Clojure actually. When going from 1.9 to 1.10 I think. We had a library that was doing an AOT for a gen-class. Even though it was only compiling the gen-class namespace and that had no requires. Transitively, it would compile the only sources not AOT compiled in Clojure 1.9, the core specs.
And somehow on 1.10 some core macro changed in a way that the 1.9 spec would fail to validate calls to it
Anyway, our solution now is our build have you list out the namespace you want to gen-class explicitly. And it will do an AOT of them, and then select only the classes file of that namespace and not of any transitive dependencies. And only include that in the Jar
that's how basically all aot tooling ends up working
that's what we do with the maven clojure plugin for the contrib libs
Ya, I feel I had checked what lein did and it didn't appear to do that. Like it does only AOT the gen-class namespaces. But then it packages everything resulting from that into the Jar
yeah, I think lein is really targeted more towards the app casee
but it's been a while since I looked at it
I should go see what the maven contrib Clojure plugin does. Might be some good learnings in there
https://github.com/talios/clojure-maven-plugin#namespace-configuration
the config is pretty fiddly to make it do exactly what you want
https://github.com/clojure/tools.reader/blob/master/pom.xml is the tools.reader config which is fairly complicated as it's both building a source jar, then aot'ing, and building an additional aot'ed jar with the assembly plugin
I do think I'm seeing some of the code that cleans up the classes that weren't for the declared namespaces, seems this does it here: https://github.com/talios/clojure-maven-plugin/blob/develop/src/main/java/com/theoryinpractise/clojure/ClojureCompilerMojo.java#L64
Hello, everyone. If anyone here uses vim, can you tell if it's normal for clojure to have different rules about how words are defined? Currently, for me, w
pretty much behaves the way I'd expect W
to work, and *
and #
match along similar definitions? I've had some plugins installed from when I tried clojure years ago and I don't know if I've missed one as I've progessively uninstalled everything Clojure or Lisp related
I do not know the answer. I suspect you may get some useful replies here, but wanted to point out that in case not, there is also a #vim channel that may be more likely to reach knowledgeable folks in that area.
Should still be considered production ready, right? What with one stable and one alpha version. BTW the fact that I’m asking is a good indicator that the 1.0.0 move was a right one :)
I would use the alpha right now
Hello, Does anyone know how to add and configure gatling-maven-plugin in project.clj https://mvnrepository.com/artifact/io.gatling/gatling-maven-plugin/3.0.5
lein doesn't use maven, and I wouldn't assume a maven plugin would be useful in a lein project
that said you could make a pom.xml (or even run lein pom to make a project pom) and configure it there
this would mean using maven in parallel with lein (or instead of it)
the plugin itself is a maven artifact, lein knows how to resolve and download the artifacts (using the underlying aether lib), but it doesn't use the maven executable which is what you need for maven plugins
lein uses the same artifact cache / download setup as maven but doesn't run maven plugins
Hi all,curl -X GET ' '"https://reqres.in/api/users?page=2' -H 'API-Key:MySecret'
damn it±
yes - it fortunately only a test one
hopefuly it is gone now?
what a mistake!!!! GRRRR
when I use this on a cli curl -X GET '"https://reqres.in/api/users?page=2' -H 'API-Key:MySecret' I get the correct results in clojure snippet ((client/get "https://reqres.in/api/users?page=2" {:body-encoding "UTF-8" :accept :json :jwt ["API-Key" "MySecret"]})) it fails now it might be the auth-type is a jwt but I cannot tell - I have tried all variations of :auth-type "oauth1" :auth and similar and cannot get it right what am I doing wrong? I have been all over the clj-http github docs but ....
why are you putting what should be a header into a :jwt
key?
:headers {"API-KEY" "SECRET"} results in failuer
Key must be integer
hold typo? on my side?
"key must be integer" means that some clojure function is doing a map lookup but you gave it a vector
hello everyone. can someone direct me to whom is in charge of keeping the ubuntu leiningen package up to date?
2.9.1-2 is listed
i tried sudo apt install leiningen-clojure
but no dice...maybe im using the wrong command tho
have you updated? sudo apt-get update
$ sudo apt-get install leiningen
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
leiningen
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 13.0 MB of archives.
After this operation, 14.9 MB of additional disk space will be used.
Get:1 bionic/universe amd64 leiningen all 2.8.1-6 [13.0 MB]
Does lein upgrade
not work after installing from apt?
Ah, then I'd go with noisesmith's suggestion of just installing it manually.
lein is very easy to manage outside the ubuntu package management system: you put a shell script in ~/bin/lein
and then use lein upgrade X
to make it run a specific version
it's just the one file (and of course making sure that file's directory is on path), as described on that page
the file is a wrapper script that uses a local cache for holding the actual jar and launching a java process
it's both the script and the downloader, in one
does it have to be on the path? i assume if i ran the file like ./bin/lein
it would install it on the machine, no?
no, it does no installation of the script itself, of course it can be run via absolute path but it doesn't put itself on path
hmmm ok sorry im getting confused by like
Run it (lein) and it will download the self-install package
it is lein
it downloads a jar that it uses
thanks @U051SS2EU for your patience w me!
Yes it works thanks - the docs stated [`"API-KEY" "SECRET"] not {"API-KEY" "SECRET"} many thanks`
but it results in a 401 Unathorised
in your original you had API-Key
- is it picky about case?
that is my bad typing
So no it is not the case
I have it consistent in the actual test item
I have tried the :digest-auth [api secret]/ the aws version/ etc.... so it is very frustrating
if the curl you showed works none of that is even relevant
that is what I find odd
I have also used httpie and got a result
Other docs on a sister site stated they use jwt but as you state - the keys are in the header
if you really want quality help, and to value people's (free) time, - Post what the intent was - Post the code you ran - Post the error you received (in full, don't leave out things you don't think consider helpful)
thanks, at 9:30 I hope i did state the problem - it is one line of clojure where I am attempting to covert a curl call to clojure and I do not understand how I convert it - It seems the api keys are referred in the header and I am using the clj-http library for the one line of code and attempting to get the syntax right . There is not much else except I receive 401 responses.
As a noobie in clojure I wish I knew how to look under the covers so to speak
If you're really just getting started with Clojure, you might have better luck asking in #beginners -- folks there will show you more patience and will be more forgiving...
ok thanks
This channel tends to assume a certain level of scientific method in debugging etc and some solid ability to read source code in libraries...