Fork me on GitHub
#clojure
<
2020-08-21
>
Jonathan Curran02:08:19

I've been out of the loop re: Clojure for ~8 years. Is there a modern/up-to-date guide to Clojure tooling and ecosystem of libraries?

seancorfield03:08:24

Probably the other "big" thing in those eight years is transducers: https://clojure.org/reference/transducers

bendy07:08:12

I find myself writing some async code, where there gets to be quite a bit of heavily nested code, only to "un-indent" at the bottom to return the channel I've been working with. Is there a Clojure function/macro that would allow me to write something like:

(with-return out-chan
  (heavily
    (nested
      (code
        (that can 
          (go on and on
            (and on
              (but the top form still returns out-chan))))))

💯 3
p-himik07:08:35

Threading macros, doto, refactoring into smaller functions, creating higher abstractions - the choice depends on the actual code.

svt09:08:57

Could someone helps me with how do I fix the vulnerabilities given by lein nvd check

otfrom09:08:50

hi, does anyone know how to reference a branch on github in deps.edn?

otfrom09:08:09

this doesn't appear to work

dali/dali           {:git/url ""
                              :tag "manual-connector-anchors"
                              :sha "875f7b40b1f8df37ca6b6e51624b96fb8122abac"}

otfrom09:08:34

I get FileNotFound when I try to require one of the namespaces

otfrom09:08:47

user=> (require '[ :as dio])
Execution error (FileNotFoundException) at user/eval2056 (REPL:1).
Could not locate dali/io__init.class, dali/io.clj or dali/io.cljc on classpath.

otfrom09:08:58

and I've not been able to find an example online to crib from

alpox09:08:26

The tag and the sha do not seem to exist for that git repository. If you always wanr the current master state you can leave away the sha and the tag

alpox09:08:10

If you want a specific release, say latesr release of dali, you can use :tag "v0.7.4"

alpox09:08:31

The sha would be for choosing a specific commit instead

otfrom09:08:36

ok. I'm trying to reference this branch manual-connector-anchors rather than master, tho I suppose I could make sure the main branch works first

alpox09:08:35

I would believe you would need https://github.com/stathissideris/dali/tree/manual-connector-anchors.git as url then but im not sure if that works

alpox09:08:55

Actually i just saw the sha is necessary, sorry about that

otfrom10:08:56

helps if I put in the right error msg and start clj by doing clj

otfrom10:08:59

user=> (require '[ :as dio])
Execution error (IllegalArgumentException) at dali.dom/eval196$loading (dom.clj:1).
Cannot open <nil> as a Reader.

dominicm10:08:48

@otfrom you're doing it right 🙂 Maybe the branch isn't fully functional?

otfrom10:08:12

@dominicm that might be it (I was having some problems using it locally as well)

otfrom10:08:35

do I need the tag and the SHA or just the SHA?

otfrom10:08:29

@dominicm cool. thx 🙂 I'll see about fixing it directly then

otfrom11:08:44

@alpox @dominicm thx. I've fixed my problem. I'm submitting a PR so that it is fixed at source as well. New code here: https://github.com/stathissideris/dali/tree/manual-connector-anchors

stathissideris16:08:30

is there a clojure library to provide simple text based interactions to the user such as:

Which database

 [1] Localhost
 [2] Remote

or type 'q' to cancel

phronmophobic16:08:29

this is probably overkill, but https://github.com/phronmophobic/terminal-todo-mvc uses membrane+https://github.com/mabe02/lanterna for building terminal UIs

stathissideris16:08:22

thanks! But I was thinking more along the lines of having a function invoked from the REPL use (read-line) to prompt you about how to proceed, not building a full-fledged app

👍 3
vlaaad16:08:01

So... readline?

stathissideris16:08:14

(defn menu [{:keys [prompt options]}]
  (let [options       (map (fn [o idx]
                             (if (string? o)
                               {:id (str (inc idx)) :text o}
                               o)) options (range))
        valid-options (set (map :id options))]
    (loop []
      (when prompt
        (println)
        (println prompt)
        (println))
      (doseq [{:keys [id text]} options]
        (println (str " [" id "]") text))
      (println)
      (println "or press <enter> to cancel")

      (let [in (str/trim (read-line))]
        (cond (= in "")
              :cancelled

              (not (valid-options in))
              (do
                (println (format "\n-- Invalid option '%s'!" in))
                (recur))

              :else
              (first (filter #(= in (:id %)) options)))))))

stathissideris16:08:43

but with some code to print the options nicely, persist if you select the wrong thing etc ☝️

stathissideris16:08:47

usage: (menu {:prompt "Which database" :options ["Localhost" "Remote" {:id "o" :text "Other"}]})

stathissideris16:08:58

thanks… do you think it might be worth releasing?

phronmophobic16:08:38

seems like a useful gist. not sure where you might be able to put it so others could find it when they are looking for it

phronmophobic16:08:30

I think the community can contribute examples to https://clojuredocs.org/clojure.core/read-line. it would make a really great example there

phronmophobic16:08:41

if you do find a good place for it. I would suggest adding (require [clojure.string :as str]) near the top

✔️ 3
phronmophobic16:08:56

although, most people would probably be able to figure that out

stathissideris16:08:51

added to clojuredocs, including the require

parrot 6
stathissideris16:08:39

I think you’re right, as a small lib it would be tricky to google for

phronmophobic16:08:52

yea, there would be some value in having a place to put snippets like yours. I saw this post on r/Clojure the other day, https://www.reddit.com/r/Clojure/comments/i6ak56/does_clojure_have_a_list_of_curated_example/

stathissideris16:08:58

but you know… maybe it would be useful as a lib now that babashka is such a big hit

phronmophobic16:08:25

the other way people might stumble across it is searching , https://grep.app/search?q=read-line&amp;filter[lang][0]=Clojure

phronmophobic16:08:52

yea, seems useful

stathissideris16:08:28

oook, yet another name to think of 😄

😆 3
andy.fingerhut17:08:36

Maybe call it 'oook' ?

😂 6
stathissideris15:08:49

@U0CMVHBL2 I was thinking something along the lines clj-read-line-menu, boring, self-descriptive and searchable!

andy.fingerhut17:08:15

searchable is good 🙂

borkdude21:08:59

$ clojure --report -e '(/ 1 0)'
{:clojure.main/message
 "Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.java:-2).\n(/ 1 0) (No such file or directory)\n",
Should this order or args work for clojure?

borkdude21:08:22

Ah I see, --report expects a file. But this does work:

$ clojure -e '(/ 1 0)' --report