This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-15
Channels
- # announcements (8)
- # beginners (65)
- # calva (25)
- # cider (11)
- # clj-kondo (9)
- # cljsrn (14)
- # clojure (103)
- # clojure-europe (15)
- # clojure-greece (1)
- # clojure-italy (28)
- # clojure-nl (39)
- # clojure-spec (9)
- # clojure-uk (28)
- # clojuredesign-podcast (37)
- # clojurescript (56)
- # cursive (41)
- # data-science (10)
- # datomic (25)
- # duct (1)
- # emacs (1)
- # events (3)
- # figwheel-main (7)
- # fulcro (9)
- # graalvm (7)
- # graphql (10)
- # jobs (2)
- # nrepl (17)
- # off-topic (40)
- # quil (12)
- # reitit (11)
- # remote-jobs (5)
- # rum (2)
- # shadow-cljs (387)
- # sql (22)
- # tools-deps (8)
- # vim (26)
- # xtdb (47)
- # yada (9)
Is there a cleaner way of building up a stack of transducers where sometimes you want to disable some transducers?
(into []
(apply
comp
(remove nil?
[(map inc)
(when false
(map inc))]))
(range 10))
Possibly obvious one
(into []
(apply
comp
(cond-> [(map inc)]
false (conj (map inc))))
(range 10))
(if false (map inc) identity)
should do it. you could shorten it by defining a util function ala #(if %1 %2 identity)
I've used something analogous to cond for conditionally doing transducers stuff, it took a bunch of predicates and transducers and only called the reducing function if the predicate matched. That is conditional per item, instead of conditional upfront on the whole pipeline. And I don't entirely recall the implementation, it might have been tricky
Hi all! I'm having trouble with setting up my mixed clojure/java project with leiningen. Is this the channel to ask this sort of stuff? 😅
great! so the thing is, I've already followed the guide on https://github.com/technomancy/leiningen/blob/master/doc/MIXED_PROJECTS.md and I've been able to run/compile my project with lein javac
, lein run
and lein compile
. However, when running lein uberjar
, I get a bunch of errors about missing dependencies during the javac phase (note that it works when I run lein javac
on its own). It looks as if during the uberjar phase dependencies were not available to the java compiler...
nevermind... figured it out! I had my dependencies declared unde the :dev
profile... 😅
I'm trying to AOT this file, but I'm getting a warning on .val
being unresolved when I start lein repl:
https://gist.github.com/borkdude/d85586985aa264431b3b10a794f97602
is the double definition an attempt to forward-declare the class for the addVar
type signature?
if I were to use tools.deps instead of lein, how would I compile the java, using a bash script I guess?
[~]> cat test.clj
(ns test)
(gen-class :name test.C)
(gen-class :name test.C :methods [["m" [] test.C]])
[~]> clj
Clojure 1.10.1
user=> (compile 'test)
Unexpected error (ClassNotFoundException) macroexpanding gen-class at (test.clj:3:1).
test.C
I actually got this solution from stackoverflow and it was marked as the accepted answer https://stackoverflow.com/questions/29329798/clojure-gen-class-returning-own-class so maybe someone should comment there 😉
yeah that's it -- genclass does only AOT so that class in a normal clojure environment is not available during compilation of the next forms
https://clojure.atlassian.net/browse/CLJ-2343 would make that code compile on non-lein environments
but still you have the problem of the compiled class referring to the wrong in-memory one
if you did an AOT compilation phase and then loaded the code it would technically work
(you'd get around the reflection error by declaring the val
field in the first genclass)
but by "works" I mean you're exploiting a shadowing bug during compilation in order to compile a correct artifact
this "shadowing during compilation" trick is precisely how deftype
does forward declaration internally, except there it's guarded by the compiler and can't escape
while in this case you're doing it manually and leaving the declared instance around during compilation
but even if you manage to somehow compile that, you'll get into all sorts of weird scenarios
altho it requires quite a bit of ugly boilerplate during compilation (there's some double compilation involved)
usually takes longer to understand the correct incantation to do something than it takes to generate a proxy class in java manually
is anyone aware of a library that provides 'reverse destructuring` ? What I have in mind is something like this:
(structure (range 8) [[[] []] []])
=> [[[0 1] [2 3]] [4 5 6 7]]
that's neat but i don't see any information conveying to put 2 in the first two vectors
is takes a sequence and a data structure and returns the sequence conformed to the given structure
- @dpsutton true, I've assumed an even fit there
- I guess there're many solutions
another example:
(structure (range 8) [[[] #{}] {}])
=> [[[0 1] #{3 2}] {4 5, 6 7}]
and I imagine it could also be made to work with predicates like odd? etc too
it would truncate I guess, or pad with nil
Feel free to join #meander if you have any questions.
also a great talk about motivations and some use cases from strange loop (https://www.youtube.com/watch?v=9fhnJpCgtUw). given by @U5K8NTHEZ here
Hi! Is there a better way to get the max of a collection of Comparable elements than Collections/max (which sadly fails on empty cols)? Thank you!
The small 'medley' library has a function for that: https://github.com/weavejester/medley/blob/1.1.0/src/medley/core.cljc#L158
Kinda depends on what value you expect to get back when you give it an empty collection, yes? The medley function linked returns nil. Some people might expect Double/NEGATIVE_INFINITY
Neg infinity only makes sense of the elements are numbers :) Nil is ideal. Thanks Jan, but I'd prefer not to add a lib for this...
I'd use the underlying JVM API via interop or a proper http lib, I am sure it's not an explicitly supported option
cool. the clj-tagsoup lib I’m using uses slurp under the hood I think, but I’ll just do the fetching myself and pass it as a string I guess
ouch, someone fix clj-tagsoup if it depends on slurp
maybe you could also get an inputstream from a proper http lib and slurp would do the right thing with that, but agreed, building on slurp is weird
@noisesmith is that last committer
haha, honestly I forgot I contributed to that project - I was fixing a bug at work and passed the fix back upstream
https://github.com/nathell/clj-tagsoup/blob/master/src/pl/danieljanus/tagsoup.clj#L52
I should have changed that try/catch into with-open while I was at it
hey) do we know of a project to generate wieldy java classes from namespaces? just a facading proxy java class with all static members. I know about implementing interfaces, so I’m asking specifically on this code gen.
I’m sorry, I mean java sources generation
If I want to try to load a namespace and catch an exception if it’s not available, which is the best exception to catch? FileNotFoundException?
reminds me of:
user=> (requiring-resolve 'foo/bar)
Execution error (FileNotFoundException) at user/eval166 (REPL:1).
If I (require 'foo.bar)
I get FNFE, but I wasn’t sure if that was always the case - there are a lot of paths there.
I’m sorry, I mean java sources generation
clojure doesn't do java code gen - I sure somebody has a lib out there somewhere that does it, but clojure generates jvm byte code directly
horrible idea: pass the clojure code through the ClojureScript compiler and then squint really hard because JavaScript is almost Java 😛
lol @borkdude have you looked at: https://github.com/EwenG/badigeon ?