This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-24
Channels
- # announcements (26)
- # babashka (9)
- # beginners (63)
- # calva (2)
- # chlorine-clover (22)
- # cider (2)
- # cljsrn (8)
- # clojure (36)
- # clojure-europe (36)
- # clojure-italy (5)
- # clojure-nl (76)
- # clojure-spec (9)
- # clojure-uk (8)
- # clojurescript (39)
- # conjure (24)
- # cursive (19)
- # data-science (1)
- # datascript (10)
- # datomic (1)
- # emacs (2)
- # events (5)
- # figwheel-main (9)
- # fulcro (21)
- # graalvm (1)
- # helix (5)
- # jobs (1)
- # jobs-discuss (1)
- # kaocha (1)
- # leiningen (4)
- # meander (2)
- # off-topic (22)
- # re-frame (16)
- # reitit (3)
- # rewrite-clj (75)
- # rum (1)
- # sci (51)
- # shadow-cljs (110)
- # tools-deps (16)
- # vrac (9)
- # xtdb (23)
How could I find all subdirectories of a certain name? Is using
methods the way to go?
I'm looking for several subdirectories, in quite a large directory. Would this be more or less efficient than any other option?
you can convert the search to a BFS and parallelize it with a core.async pipeline, which maintains order
@UFLJN302F You could also follow this example. https://clojuredocs.org/clojure.core/file-seq#example-59f3948ee4b0a08026c48c79
You would need to change a few things like change
(filter #(.isFile %))
to (remove #(.isFile %))
since you're looking for directories. The grammar-matcher
is likely what you're looking for. I wouldn't jump to core async just yet, see if an adaptation of the above example is sufficient for your needs.
Using java interop might be faster: https://docs.oracle.com/javase/tutorial/essential/io/walk.html It depends on your use case but here I was trying to discover git repositories in a directory and it was significantly faster than naive list files and filter (although uglier):
(defn discover-no-subdirs [path]
(let [git-repos (atom [])]
(java.nio.file.Files/walkFileTree (java.nio.file.Paths/get path (make-array String 0))
(proxy [java.nio.file.SimpleFileVisitor] []
(preVisitDirectory [dir attrs]
(if (-> (.resolve dir ".git") .toFile .exists)
(do
(swap! git-repos conj (str dir))
java.nio.file.FileVisitResult/SKIP_SUBTREE)
java.nio.file.FileVisitResult/CONTINUE))))
@git-repos))
Now that we have extend-with-meta
, should I prefer pass "functions as parameter" with protocols
(my/lib (with-meta {::data 42}
`{my/operation (fn [])}))
Over pass "as data"
(my/lib {::my/data 42
::my/operation (fn [])})
In a shot think:
:thumbsup: Better errors: No implementation of method
is way clear that NPE
âť“ print: "Dumb" print methods, like prn
or str
may "hidden"/confuse developers in debugging tasks. But "richer" debuggers like REBL/cljs-devtools have dedicated "metadata" area
:thumbsdown: A bit worse do write.
:thumbsup: Serialize: if you need to write a map on wire (json/transit/edn), it will not include functions by default.
âť“ harder do compose: should we always use alter-meta assoc
over with-meta
to not unintentionally remove a implementation?
What you think about that?as usual, it probably depends on the rest of the context. :) one downside of the latter is fn's dont have good equality semantics
Can someone tell me what's wrong with this namespace declaration? Clojure complains that there's "extra input":
(ns io.the-network.lib.segment
(:require
#?@(:clj
[]
:cljs
[[io.the-network.lib.form :as lib-form]])))
I can't for the life of me see what's wrong. I also manually re-typed this twice now.I tried putting an empty vector in there, so it is :clj [[]]
but that gives the same error
At least I have other namespaces with an empty require vector and it works fine there. Though that is in the :cljs part there
tmp ❯❯❯ clj
Clojure 1.10.1
user=> (ns bob (:require []))
Syntax error macroexpanding clojure.core/ns at (REPL:1:1).
((:require [])) - failed: Extra input spec: :clojure.core.specs.alpha/ns-form
user=>
Well, thanks! I at first ruled something like that out, because at first, clj even complained about the ns declaration without any require whatsoever.
(match [event auth]
["login" _] "LoginAttempt"
["login" "success"] "LoginSuccess"
["login" "failure"] "LoginFailure"
How can I coax clojure to return a list of matching results? I realize I could just make the result a list eg: ("LoginAttempt" "LoginFailure"), but I think for coding/readability, I'd prefer to be able to list each result separately.Hi Clojurists! I'm having a problem here with reading files on a project.
(defn custom-gen []
(fn []
(s/gen #{x})
(-> (slurp "test/resources/some-file.edn")
edn/read-string
:response
:body)))
the problem is that this project is a lib of another one, so we have a problem regarding the file path.
when the main project tries to compile the lib, it cannot find the file.
what should i use instead of slurp
here?
I know that slurp uses a reader
that reads files relative to the project root, but the project root depends on running context right?looks like there is a discarded form in your example (s/gen #{x})
seems to be thrown away
i've redacted the code to show here, dunno if i've balanced parenthesis correctly and so on
but the main thing here is the slurp
argument file path
there's also
so if you move your edn file into resources directory (usually <project dir>/resources
) you can do (slurp (
thanks, I'll try that
(defmethod parse-query :text
[text]
(->> text
(clojure.string/split-lines)
(map #(rest (re-find #"(chr.*):(\d+)-(\d+)" %)))
(map parse-row)))
And I was wondering as to what is the idiomatic way to go about handling errors in Clojure? In Haskell I'd do something with Monads obviously, and the cats library looks like a nice solution, but is this the way to go?
instaparse is clojure parsing library which has a pretty idiomatic way to handle errors: https://github.com/engelberg/instaparse#parse-errors
Hi folks! I am trying to describe namespaced keywords and maps for rewrite-cljc with simple terms.
I might have missed it but I don’t see definitive terminology in Clojure docs.
Here’s my current shot at it:
• current-namespaced for ::foo
• alias-namespaced for ::alias/foo
• literal-namespaced for prefix-ns/foo
I think the first 2 are easy to grok but am not crazy about literal-namespaced maybe prefix-namespaced? Thoughts?
the first two are "auto-resolved keywords", with current namespace and alias namespace, the latter is just a qualified keyword
:foo is an unqualified keyword
and important that auto-resolved keywords are syntactic sugar resolved by the reader, just shorthand for writing qualified keywords
Thanks so much @alexmiller! I should probably be more wordy for the first 2 then.
• “auto-resolved current namespace” for ::foo
• “auto-resolved alias namespace” for ::alias/foo
• “qualified” for :prefix-ns/foo
• “unqualified” for :foo
And I’ll add your important note about syntactic sugar.