This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-25
Channels
- # announcements (8)
- # babashka (58)
- # beginners (59)
- # biff (4)
- # calva (39)
- # cider (2)
- # clj-kondo (8)
- # clj-together (4)
- # cljdoc (5)
- # cljsrn (1)
- # clojure (60)
- # clojure-australia (2)
- # clojure-europe (16)
- # clojure-nl (1)
- # clojure-norway (3)
- # clojurescript (13)
- # conjure (10)
- # cursive (9)
- # datomic (5)
- # dev-tooling (1)
- # emacs (6)
- # events (1)
- # graalvm (38)
- # graphql (5)
- # joyride (1)
- # kaocha (3)
- # lsp (23)
- # malli (2)
- # mount (2)
- # off-topic (31)
- # other-languages (13)
- # pathom (3)
- # polylith (12)
- # portal (4)
- # practicalli (22)
- # re-frame (6)
- # reagent (3)
- # releases (3)
- # sql (4)
- # squint (3)
- # tools-build (10)
- # tools-deps (10)
- # xtdb (4)
On teaching Clojure to kids. What do you recommend as a low-entry drawing/animation library for young teens? We have already tried maria.cloud, but there are a bunch of issues that prevent us from going forward. Ideally, I would like to have smth with minimal installation, like babashka, but I did not find a good drawing lib. Most kids are using Windows. Installing Java and lein on Windows is a chore for them : )
Can you expand on why Maria isn't working for you? It was kind of designed for this setting I think. cc @U07SQTAEM @U050RLRRQ
@U96LS78UV Does quill work with babashka?
quill runs in the browser right? I think one could make a quill playground with SCI like it's done here for reagent / re-frame https://babashka.org/scittle/codemirror.html
it seems quil already has a playground: http://quil.info/sketches/local/6991a838de6b23c7eea3a7331c949dcedba93ac9772b971cbc0c29767e1bbac7
@U04V15CAJ yeah forgot that quil had this. I only used from Clojure.
as we are midway through a new implementation of Maria.cloud, definitely interested in what issues we could resolve
scittle
with quill will be genuinely amazing and something I’d be interested in.
@U8VE0UBBR you could fork scittle, add quill as a plugin and publish @U8VE0UBBR/scittle-quilll on npm if you want
then people can also use it on http://codepen.io :)
@U04V15CAJ Maria.cloud has a rathe awkward interface they struggle with. But mostly saving, having a real repl, I can elaborate if some wants
Perhaps setting up Calva + the dependency for them would be easiest. calva works without any further installation of clj tools, since it uses deps.clj as a fallback
If those things are too hard, maybe clojure will also be too hard. I'm not an expert in these children playgrounds. Perhaps Dr. Racket has something?
you don't need to install lein if you use deps.edn
- then it uses deps.clj
as an automatic fallback
I keep wondering if CLJ is indeed to complex for them. But most of them have a grasp of it after 4 lessons. Would be a shame to drop it now.
One simple hack is to use p5.js
with scittle. Invoke the drawing parts as js/rect
and js/fill
….
Everything I've heard is that people with no pre-conceptions about programming tend to take to Clojure fairly easily, if you can get past the initial setup bumps
Is it possible to avoid writing what amounts to ~1 KB string to a file and instead give the Writer that expects a file handle something that is completely in memory such as a stream backed by a var or something? I currently have this ugly thing taking Prometheus metrics from HikariCP:
(let [f (File/createTempFile "hikari-metrics" ".txt")
_ (with-open [w (io/writer f)]
(TextFormat/write004 w (.metricFamilySamples (CollectorRegistry/defaultRegistry))))
out (slurp f)]
(.delete f)
out)
It works, but it really is quite ugly and likely has edge cases I cannot forsee.Can you use a StringWriter?
I am not sure, how do I find out? I have this solution that kind of does what I want, but I am ready to learn an even better approach.
(with-open [baos (ByteArrayOutputStream.)
w (io/writer baos)]
(TextFormat/write004 w (.metricFamilySamples (CollectorRegistry/defaultRegistry)))
(.close w)
(.toString baos StandardCharsets/UTF_8))
This really wasn't obvious to me.Here is the code to TextFormat/write004 https://github.com/prometheus/client_java/blob/main/simpleclient_common/src/main/java/io/prometheus/client/exporter/common/TextFormat.java
Well from memory.... (let [writer (StringWriter.)] (TextFormat/write004 w xxxxx) (.toString writer). You don't need to bother closing a StringWriter and just get the contents after the write.
clojure's io/writer is fine for many purposes, but not sure it can write to a string, so just use java interop and create a stringwriter yourself and pass it whereever you want a Writer?
e,g.
(defn write-004-to-string [mfs]
(let [w (
(TextFormat/write004 w mfs)
(.toString w)))
or (-> (http://java.io.StringWriter.) (TextFormat/write004 mfs) (.toString)) as a one-liner 😉
Unfortunatelly, that doesn't seem to work. The TextFormat/write004 returns nil when used like that. The writer wrapped ByteArrayOutputStream works. 🙂
Write004 looks as if it will always return nil. You have to return .toString on your writer?
Otherwise I’m not sure sorry!
This works for me....
(let [writer (
(.write writer "Hi there")
(.toString writer))
Ah, yes. Sure.
(let [sw (StringWriter.)
_ (TextFormat/write004 sw (.metricFamilySamples (CollectorRegistry/defaultRegistry)))]
(.toString sw))
worksIt is also very slightly faster. Thank you for the help and patience!
https://clojure.org/reference/deps_and_cli#find-versions can take a :lib
value. What are the possible paths for obtaining this value?
there is no magical source - it's either a Maven groupId/artifactId
or a git id per https://clojure.org/reference/deps_and_cli#_coord_attributes
so org.clojure/data.json
or io.github.clojure/tools.build
for example
I have built some experimental "search" type functionality for this but it is pretty magical and gross
I suppose that strategy doesn't work because git libs get translated to some ~/.gitlibs/libs/*
path, which doesn't communicate anything about inferred repo URL, so there's no way of knowing the which of the lib formats to use.
Well if you have the libs in an existing deps.edn that would be an existing non magical source
clj -X:deps list
will show you those
Thanks very much, @U064X3EF3. That's about all the info I need about this at the moment.
if you clj -X:deps list :format :edn
you get a lot more info in the lib map that is returned (map of lib to coord). if you filter just the coords that have empty :dependents, everything left is a top level dep, ala (reduce-kv (fn [ls lib coord] (if (seq (:dependents coord)) ls (conj ls lib))) [] libs)
Thanks, @U064X3EF3. That is very helpful. It still requires downloading the deps, but I'll create a request for that.
I've defined this utility function but I can't help thinking there's a more idomatic way to do this:
(defn and-then>>
"Returns (true-fn v) if v is truth-y otherwise returns v."
[true-fn v]
(if v (true-fn v) v))
My use case looks like this:
(->> pairs
(remove (fn [[_ v]] (#{"NONE" "NO"} v)))
(map (fn [[k v]] (str (-> k name (str/replace "_" " ") capitalize-words) ": " v)))
(map li)
seq
(and-then>> ul))
The idea being that if the seq after that last map
is empty we'll get nil
but if it has items they'll be wrapped by the ul
function.
AND..... just answered my own question. I was looking for the some->>
macro:
(some->> pairs
(remove (fn [[_ v]] (#{"NONE" "NO"} v)))
(map (fn [[k v]] (str (-> k name (str/replace "_" " ") capitalize-words) ": " v)))
(map li)
seq
ul)
LOL. JUST saw that and updated my message. Thanks!
Nice, I’ve never seen this function before, but I am sure I will get some good use out of it as well.
logically, yes (you should be able to do it only by downloading pom files which provide the dep info), but that is not an option provided by tools.deps
if you'd be interested in such a thing, a request at https://ask.clojure.org would be the place to put it (but would help to understand the use case more)
@U064X3EF3 I'm asking this as a bit of an xy problem. Please give me a moment to clarify.
What I'm really after is for a way to identify what deps a project is using without creating the project's runtime or downloading all of its dependencies. I want this information to make it easier to link projects together for my Clojure code explorer project. At the moment, I depend on grepping deps.edn for specific dependencies, and then matching ns+fn usages in the dependent project to ns+fn definitions in the dependency. It works, but not great.
I think that if the list of :lib
s could easily be exported for a given project without downloading deps or creating a runtime, we could get this information included in clojure-lsp's output -- maybe even in clj-kondo, and it would provide for better linkability between projects in the Clojure ecosystem.
Do you think this is worth submitting a request, or should I explore other angles?
Only the top level dep info is actually in the project. To get full transitive deps, you need to interrogate other sources.
If you’re just looking to do something like -X:deps list but download only metadata, not jars. I think that could be added pretty easily