This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-28
Channels
- # announcements (13)
- # babashka (7)
- # beginners (35)
- # calva (23)
- # chlorine-clover (6)
- # cider (12)
- # clj-kondo (6)
- # clojure (31)
- # clojure-dev (20)
- # clojure-europe (4)
- # clojure-norway (4)
- # clojure-uk (1)
- # clojurescript (62)
- # fulcro (6)
- # google-cloud (1)
- # lsp (2)
- # malli (13)
- # meander (6)
- # music (1)
- # off-topic (19)
- # practicalli (2)
- # re-frame (7)
- # reagent (25)
- # reitit (5)
- # releases (1)
- # reveal (3)
- # shadow-cljs (90)
- # tools-build (18)
- # tools-deps (1)
Could you please share an example of the data structure?
Clojure core functions are enough to perform any kind of data processing.
Usually you’d read the file, convert it into a Clojure data structure and use the core fns for processing. If it’s a nested map, take a look at functions like select-keys
, reduce-kv
, get-in
, etc.
If it’s a very large file then of course it gets more complicated, but the core ideas still remain (mostly) the same.
#beginners is a better channel for this question @U02RRUT1ALQ And we need an example: 1. what does the file look like and 2. what result do you expect
Furthermore, like @U0505RKEL said, your question includes a couple or problems: 1. Read a file 2. Convert it to a clojure data structure 3. Transform the data structure to get the result you want Try to find out which part of the process you're struggling with and come up with a more specific question.
Hopefully someone can explain this to me.
I have a case
which tries to match on a specific map, ala:
(case result
{:version supported-version} (prn "success"))
This will not work. The supported-version
statement has been defined earlier, but it seems like it will not be compiled into the clause. Because, when I replace supported-version
with the string which has been assigned to it, then does work.Case statements are symbolically compiled. It doesn't interpolate the defined symbol
Does this mean that the clojure compiler will not make simple def
statements compile-time constants? I would assume that for the case
statement, it would resolve it at compile time.
As a rule of thumb, use cond, not case. In Clojure, case's dispatch keys are literals, which leads to duplication (as we can't use constants). In ClojureScript, case opportunistically uses constants if they have been defined, which leads to surprises when a case changes behavior when constants' definitions are added and removed. Considering the brittle idiosyncrasy of Clojurescript's case, the fact that case isn't portable from clj to cljs, and the ideal that just about any Clojure code ought to be repurposeable in ClojureScript, you might as well avoid case entirely. Use cond.
How do you use the Java method reference operator (`::`) in Clojure interop?
fair enough 🙂
There is no equivalent. You need to reify the interface you are targetting explicitly.
(reify Function
(apply [_ x]
(Code ... x)))
Or use the method handle api (which is way more cumbersome, but dynamc)
The MethodHandle api isn't sufficient, still need to take the MH and adapt it into the correct interface
When you do Class::staticMethod or Object::instanceMethod, java tears off a MethodHandle then adapts it into the target interface
Just make sure that the user.clj
is not in your CLASSPATH
when running tests. Perhaps via appropriate aliases.
Somehow it got invoked when I ran clojure test from intellij. Probably the cursive plugin invoked it. Thanks!
So, I'm trying to write an extension for https://guacamole.apache.org/ in clojure and I've run into a rather annoying roadblock: Guacamole loads each extension using a dedicated classloader (which prefers the extension's resources over its own) but it doesn't set the thread context. The upshot is, Clojure's runtime classes load but when it tries to load clojure core etc. that fails. I can vaguely imagine a couple of ways I could solve this, all requiring I write the entrypoint of my extension as a java shim. However, I've no idea what the right approach would be, if there even is one. Does anyone have suggestions?
As a basic idea, I could capture the context classloader in the constructor of my entrypoint class, set it to the entrypoint's classloader, call out to clojure's load routines myself, and then reset the context back again? I worry about code trying to load lazily or such though...
:thinking_face: or maybe it'd be sufficient to set *use-context-classloader*
to nil somehow, also in that constructor...
A long time ago, for some vaguely similarly issue with writing Jenkins plugins in clojure I wrote this code https://github.com/hiredman/jenkins-clojure-injector/blob/master/src/leiningen/jpi.clj which avoids writing java by instead using clojure's vendored copy of the asm library to generate bytecode
I... think I follow what you're doing there, but I don't think I could bring myself to attempt adapting that to be honest 😅
I assume it did, it has been a long time, I vaguely recall playing with https://github.com/hiredman/jenkins-nrepl, so it must have worked