This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-03-29
Channels
- # announcements (9)
- # aws (1)
- # beginners (133)
- # boot (2)
- # calva (94)
- # cider (48)
- # cljdoc (7)
- # cljsrn (22)
- # clojure (128)
- # clojure-europe (22)
- # clojure-finland (7)
- # clojure-greece (6)
- # clojure-losangeles (3)
- # clojure-nl (81)
- # clojure-spec (30)
- # clojure-uk (60)
- # clojure-ukraine (1)
- # clojurescript (45)
- # core-async (26)
- # cursive (18)
- # datomic (12)
- # defnpodcast (1)
- # duct (4)
- # editors (4)
- # emacs (6)
- # fulcro (37)
- # graphql (4)
- # jobs (2)
- # jobs-rus (1)
- # juxt (7)
- # kaocha (2)
- # leiningen (1)
- # nrepl (22)
- # off-topic (2)
- # re-frame (16)
- # reagent (8)
- # reitit (22)
- # ring-swagger (5)
- # shadow-cljs (81)
- # tools-deps (4)
Good day everyone
Could someone help me with why having an nREPL is so powerful?
and why other programming languages don’t have it
from the interwebs I can see it allows you to connect to it with a client (VSCode in my case) and remote execute code
yeah, its an instant feedback loop, I send code to my repl to “test” it the entire day
thank you Lennart
@naxels I think first, Separate the concept of having a REPL from the concept of having a Network REPL Having a REPL is like having a workshop, you use tools in real time as you build, so as Lennart said - you get an instant feedback loop while you are constructing, rather than making changes, compiling etc NREPL is actually useful in many contexts, from editors to production code, anywhere you might want to send snippets of clojure to a remote REPL session. Sometimes the remote is just on your local machine and your text editor integration uses it to improve your dev experience. Sometimes the remote is a running instance of your production software and you want to issue control commands, inspect your software as it runs, or even hot swap code.
in learning Clojure, I use the REPL a lot, much much more than I did in Ruby/Go
locally, it provides a much faster feedback cycle, and in prod, it's an invaluable debugging tool
now that I use VSCode for Clojure, I was curious what the value of the nREPL was
that is answered, i just need to learn how to work with it ha
Yeah, if you are just using the command line REPL, you have not experienced the real power yet
it's a full on development lifestyle with editor integration (which tends to use nrepl)
i actually installed Calva
and am curious how the reload your file works
i did find the commands to Evaluate
i think it’s called Eval on Save?
(it’s on by default for me)
lots to learn ha
same as Paredit
yes i’m using lein and am connected to the nREPL
i get the feeling this is one of those things that ones you figured it out you never want to go back ha
yes it is
let me try
I'm paraphrasing here too, I'd have to run through it all again to get it exactly right I'm sure 🙃
do you know of a quick tutorial to get the hang of it?
i tried the above, however doesn’t work for me
(unable to resolve symbol error)
yes it does
aaah i now also see that VSCode had already started a separate terminal for nREPL automatically labelled “Clojure REPL”
i get errors on the namespace
fixed*
i don’t see any message/output when i evaluate the file
have a couple of println’s in tehre
yes, the nREPL is green
err orange/yellowish
haha, thats surprisingly dutch, you may be interested in #clojure-nl
oh… already there
haha yeah just found/joined the channel, are you Dutch?
name shows it a bit, I guess
i had a file open, but not in a project
i found a free Clojure Udemy course i started to follow
it didn’t mention anything about a project yet
but i got VSCode & Calva setup
read clojure for the brave and true!
(also online)
yeah i found that one
will try 🙂
thanks for your help guys! lot’s of learning ahead of me
bought a couple of books
want to learn Functional Programming
yes, watched quite some of those
that’s one of the key reasons i came to Clojure out of the available languages
like someone mentioned in a blog post, Rich Hickey is a ‘feature’ ha
I wrote these functions, then realized: all data I'll apply artifacts
to will have :results
data, but not necessarily :screenshots
or :logs
. How can I rewrite this so that those values will be nil
instead of throwing errors when I try and listFiles
of nil?
(def ffilter (comp first filter))
(defn artifacts
[run-on-disk]
(let [contents (.listFiles run-on-disk)
result? (fn [f] (= "junitresults.xml" (.getName f)))
screenshots? (fn [f] (= "screenshots" (.getName f)))
logs? (fn [f] (= "logs" (.getName f)))]
{:results (ffilter result? contents)
:screenshots (.listFiles (ffilter screenshots? contents))
:logs (.listFiles (ffilter logs? contents))}))
(and open to other improvements! this is a lot better than what it's replacing but could be better)
:thinking_face: I think I'm using ffilter
in the wrong place, for one.... maybe I'll figure this out if I stare at it long enough
having nil keys in a map is not very idiomatic
its more idiomatic to just omit keys that are nil
in that case, take a look at cond->
also, while you are at it, there is letfn
to define locally scoped functions
this does seem closer:
(defn artifacts-2
[run-on-disk]
(let [contents (.listFiles run-on-disk)
result? (fn [f] (= "junitresults.xml" (.getName f)))
screenshots? (fn [f] (= "screenshots" (.getName f)))
logs? (fn [f] (= "logs" (.getName f)))]
(cond-> {:results (ffilter result? contents)}
(ffilter screenshots? contents) (assoc :screenshots (.listFiles (ffilter screenshots? contents))))))
even nicer!
well I'm very happy to have finally made a cond->
work with
(defn artifacts-2
[run-on-disk]
(letfn [(results? [f] (= "junitresults.xml" (.getName f)))
(screenshots? [f] (= "screenshots" (.getName f)))
(logs? [f] (= "logs" (.getName f)))]
(let [contents (.listFiles run-on-disk)]
(cond-> {}
(ffilter results? contents) (assoc :results (ffilter results? contents))
(ffilter logs? contents) (assoc :logs (.listFiles (ffilter logs? contents)))
(ffilter screenshots? contents) (assoc :screenshots (.listFiles (ffilter screenshots? contents)))))))
at least you learned something new along the way!
Hi everyone, I'm writing a function that takes a map and parses it into a sequence of api-calls (which are to be called later). I have something like this currently:
(defn parse-blueprint
[blueprint]
(when (check-keys blueprint)
(let [[_ api-calls] (-> [blueprint []]
(extract-draft)
(extract-sections)
(extract-quotes)
(extract-lines)]
(when-not (empty? api-calls)
api-calls))))
The extract-x
functions take in a map and a vector and returns the unmodified map and vector with new stuff appended.
I'm wondering what the correct/idomatic way to do something like this would be?@naxels pardon if someone mentioned already, but a subtle key to why clojure's repl is so useful is that the language itself is designed so that iterated development in a repl can redefine things in a "flow" friendly way
many languages have some sort of repl, with many of them the rules in the repl are subtly different from what works in source files, or there are key things you can't pull apart / examine / redefine in a repl
clojure isn't perfect on this, but far ahead of most compiled languages
hm, I'm not quite there yet --- this seems nice for the cases that have all the results, but I'm NPEing in the case where there's only :results---
(defn artifacts-4
[run-on-disk]
(let [contents (.listFiles run-on-disk)]
(cond-> (group-by #(.getName %) contents)
"junitresults.xml" (update "junitresults.xml" first)
"logs" (update "logs" (fn [part] (.listFiles (first part))))
"screenshots" (update "screenshots" (fn [part] (.listFiles (first part))))
true (rename-keys {"logs" :logs
"screenshots" :screenshots
"junitresults.xml" :results}))))
you need something in (fn [part] ...)
that deals with (first part) being nil
huh. I thought that was covered by the first half of the line. I thought the update would happen if and only if there was something under that key
hmm... you could be right
ooooh I was thinking those keys would act like functions, but I probably have to do (fn [m] (m "screenshots"))
current hypothesis: cond-> is only threading thru the 'action' half of the lines, not the 'assertion' halves
is there a threading macro that hands the passed value to the condition as well as the action?
there's a version of cond-> that passes changes to the conditions from some library, can't recall precisely at the moment
If I just bind that collection of partitions...
(defn artifacts-5
[run-on-disk]
(let [contents (.listFiles run-on-disk)
m (group-by #(.getName %) contents)]
(cond-> m
(m "junitresults.xml") (update "junitresults.xml" first)
(m "logs") (update "logs" (fn [part] (.listFiles (first part))))
(m "screenshots") (update "screenshots" (fn [part] (.listFiles (first part))))
true (rename-keys {"logs" :logs
"screenshots" :screenshots
"junitresults.xml" :results}))))
ahh, the key "junitresults.xml" is always truthy
that's your issue
so yeah, looking it up in m fixes it