Fork me on GitHub

How could I find all subdirectories of a certain name? Is using methods the way to go?


file-seq + filter should get you there


Thank you!


I'm looking for several subdirectories, in quite a large directory. Would this be more or less efficient than any other option?

Ben Sless10:08:01

you can convert the search to a BFS and parallelize it with a core.async pipeline, which maintains order


Will take a look into it

Ben Sless11:08:59

feel free to ping if you need

Joe Lane14:08:15

@UFLJN302F You could also follow this example. 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: 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)
                                              (swap! git-repos conj (str dir))

👍 3

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?

Alex Miller (Clojure team)15:08:45

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
   #[email protected](:clj
       [[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.


your clj branch will end up just (:require) i think

👍 3

I tried putting an empty vector in there, so it is :clj [[]] but that gives the same error


And I am pretty sure (:require []) is valid, no?


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


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")    
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


so if you move your edn file into resources directory (usually <project dir>/resources) you can do (slurp ( "test/some-file.edn"))


thanks, I'll try that


I'm writing a simple parse for different types of input and it can fail.


(defmethod parse-query :text
  (->> text
       (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:


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?

Alex Miller (Clojure team)21:08:07

the first two are "auto-resolved keywords", with current namespace and alias namespace, the latter is just a qualified keyword

Alex Miller (Clojure team)21:08:29

:foo is an unqualified keyword

Alex Miller (Clojure team)21:08:18

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.