This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-05-16
Channels
- # announcements (5)
- # aws (34)
- # beginners (145)
- # cider (48)
- # circleci (8)
- # clara (7)
- # clj-kondo (28)
- # cljs-dev (75)
- # cljsrn (4)
- # clojure (325)
- # clojure-czech (10)
- # clojure-europe (5)
- # clojure-italy (4)
- # clojure-nl (4)
- # clojure-spec (6)
- # clojure-sweden (3)
- # clojure-uk (70)
- # clojurescript (18)
- # clr (1)
- # community-development (2)
- # cursive (38)
- # data-science (7)
- # datascript (14)
- # datomic (22)
- # emacs (2)
- # figwheel (1)
- # fulcro (6)
- # graalvm (22)
- # graphql (11)
- # hoplon (12)
- # jackdaw (8)
- # jobs-discuss (16)
- # juxt (5)
- # leiningen (19)
- # luminus (5)
- # nrepl (2)
- # nyc (1)
- # off-topic (6)
- # overtone (2)
- # pedestal (10)
- # re-frame (6)
- # reagent (8)
- # reitit (1)
- # rewrite-clj (43)
- # ring (2)
- # shadow-cljs (124)
- # testing (1)
- # vim (22)
- # xtdb (77)
- # yada (4)
i'm reading weird characters guide, and namespace syntax for map literals doesn't expand like in example. Why? https://gyazo.com/54b9207c6ae4b5d4c35de9da822f25cb.png
its been a bit but this is a dynamic binding and i think nrepl cranks up a new repl for each evaluation under the hood and it either misses this binding or it just doesn't "stick" for some other reason
I think that may have actually changed
I seem to recall the nrepl behavior changed in one of the more recent builds
alex is correct they fixed it in 6.0 (set! *print-namespace-maps* false)
works just fine
the command above I think will work in latest lein repl
what am i missing? https://gyazo.com/aaf03961d100241f21ce29adaa9353d3.png
the def doesn't get used inside quote - the ` reader macro treats it specially and it should error if it's exposed outside that context
the special form for ` is where all the unquote logic lives, and all the special forms are in the java code in the compiler
oh I'm wrong it moved - that's commented out in Compiler.java. I am looking for where it is defined now
it's a part of LispReader.java https://github.com/clojure/clojure/blob/06097b1369c502090be6489be27cc280633cb1bd/src/jvm/clojure/lang/LispReader.java#L988
that was syntax quote, this is unquote https://github.com/clojure/clojure/blob/06097b1369c502090be6489be27cc280633cb1bd/src/jvm/clojure/lang/LispReader.java#L1168
syntax quote checks isUnquote and UnquoteReader creates the object that would return true for that predicate
I have a lazy seqence (two dimensional vector) and I want to take each element from it and convert it into hashmap (using zipmap funcion)
When I execute: (doall (map println (csv/read-csv reader))
I see the list of of vectors (e.g. [a b c] [q w e] ...) I want to use on each vector the zipmap method but I don't know to to do it.
map println ...
will just return sequence of nil
s.
I'm not sure I fully understand your question but if you want to "zipmap" with the csv header then you could do something like this:
(map #(zipmap ["field1" "field2" "field3"] %1)
'(["a" "b" "c"] [1 2 3] [10 20 30]))
({"field1" "a", "field2" "b", "field3" "c"}
{"field1" 1, "field2" 2, "field3" 3}
{"field1" 10, "field2" 20, "field3" 30})
I am experiencing some problems to setup my dev
environment here. I have a user.clj
file where I setup functions to start, stop and reset
similar to those explained here http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded
however, the user
namespace, cannot require my custom namespace using the function refresh
it says error-while-loading user :cause "No namespace: fabrik.system.core"
however, if I execute manually it works just fine
Parallelism question: I have a program that iterate
s over a {}
that contains the state of the program (ร la: https://aphyr.com/posts/312-clojure-from-the-ground-up-modeling). The iterate
consists of a comp
(pipeline) of functions that take the state hash-map as their sole input argument, destructure the values they need, and then merge
their result back into the state. The state is continually fed through the pipeline until some terminating condition is met.
I want to write a version that parallelizes the iterations. They just need a seed value to start, but processing their output requires the processed output of past iterations (this does not have to be sequential). Once I rewrite the main function to handle the parallel task delegation, I can accomplish this without messing with the current code too much, by just making state into an atom
that is accessible to all threads, and changing all the (merge state result)
s to (swap! state merge result)
, right?
Hello Clojure beginners! I am writing a book on Clojure and I am looking for some Clojure beginners to review parts of the manuscript. The book is already available online in an early access version. 5 Units already published https://www.manning.com/books/get-programming-with-clojure?a_aid=viebel&a_bid=399d9d64 Please send me a direct message if you are interested with reviewing parts of the book
Hello! Is it possible to have edn include other edn files? For example in duct
you need to define the graphql schema in config.edn
. Which is fine but itโs a lot of noise for the duct config and Iโd like to separate those two (being duct config and graphql schema)
For example here you can see the graphql schema inside of config.edn https://github.com/kakao/duct-lacinia/blob/master/examples/starwars/resources/starwars/config.edn
Recent versions of duct also have the #duct/include
reader, have you looked at that? I don't see it documented in his README though...
I'm pretty sure :duct.core/include
is deprecated
I have a deployment question. I'm going through the luminus
tutorial of a simple guestbook. Works great in dev and repl mode on my machine.
I dockered it up, and deployed in on my local network and all I get is a Error 500
. The about page works as it should. I have no clue where to start looking. The Docker logs are just "Attaching to guestbook"
the 500 error should have had an associated stack trace and exception
All it says is "Error: 500 Something very bad has happened! We've dispatched a team of highly trained gnomes to take care of the problem."
that's in the browser I assume
there should be something else from the app
it could be that you have a badly configured logger or an over eager try/catch preventing you from seeing the issue
what's happening inside docker?
Normally I look at the docker logs, and I am not getting any info there.
Let me run it in -it
mode
I've heard people praise namespaced keywords, but I've yet to grok them. How do you generally manage them? Specifically, 1. how do you refer to them from other namespaces without being overly verbose and brittle, e.g. :some.other.namespace/my-keyword
, and 2. how do you avoid referring to a non-existent keyword? e.g. (defmethod x :mispeled-kyword ...) (x :misspelled-keyword)
Hmm @noisesmith I'm not able to find any logs...any clue how>
it really depends on how your app is set up, and how docker is set up
one thing you could test is putting (/ 1 0)
into your entry point function and seeing if there's any output you can find in logs or stdio
also, you could run the repl inside the docker container to see if it's something that's visible there, maybe caused by some difference between how you run in the container and how you run during development
Finally found the logs! I had to add RUN apk add --no-cache bash
to the dockerfile. Then get to the bash...I'll mount the volume next.
The table isn't there so It doesn't look like its migrating.
the first thing to understand is keyword namespaces are not connected to code namespaces
a good analogy is the namespace part of a keyword is like a sql table name, where the name part is like a column name
so just like you don't go around naming tables after code namespaces that use them, you shouldn't go around using code namespace names for keyword namespaces
That makes tons of sense, but ::keywords are auto-namespace based on where they're defined, what's the use case for those?
the docs for things like spec use it for concision, but for most code it makes things too brittle
until we can easily alias symbols for use with ::
without other effects, it makes things far too brittle
I have no experience with this, so asking out of curiosity what kind of brittleness can occur if, for example, one creates a namespace that has absolutely no code in it, and is created purely for the purposes of creating an alias foo so that namespaces keywords can use ::foo/kw-name
?
I guess that approach is limited to projects that actually create that namespace, and other projects receiving/using such namespaced keywords need to use :full.kw.namespace/kw-name
anyway?
thereโs the mechanical aspect of creating the namespace. think it kind of offends my sensibilities in some way. thereโs also the fact that you pointed out where itโs portability is poor (e.g. across a wire).
mainly my experience is, Iโve started off using ::kw-name and then regretted it later when I need to split the namespace up or move certain things out of it
Hey guys! I have an multi dime vector representing a game map. For ex:
`(def game
[ ["X" "X" "X"]
["X" "X" "X"]
["X" "X" "X"] ])`
I wanted to serialize it in the console properly and i kind of achieved this with this fn:
(reduce #(str %1 \newline (str/join " " %2)) game)
(there's still a little bug in the first vector row).
But now i want to add the coordinates in the serialization to become like this:
` 1 2 3
1 X X X
2 X X X
3 X X X `
How would you do that? I tried to add a (range 50) vector to the first item after adding an item to first item of a row with a for function, but it didnt work quite well, and the code looked kind of imperative....
(str/join \newline
(map #(str/join " " (cons %1 %2))
(cons " " (range))
(cons (range 3) game)))
for building strings I believe doing string/join
on a collection is generally better than incrementally building it up via reduce
this is so great. Thank you @UCPS050BV
Is it possible to call one specific deftest in REPL?
(reduce (fn [s {:keys [index row]}] (str s \newline index (str/join " " row))) " 1 2 3" (map-indexed (fn [i e] {:index i :row e}) game)
- perhaps
it's a lot messier than what you started with
... and what's the new deps.edn way to run all tests in terminal (and get a nice summary of tests etc - as Leiningen provided earlier)?
Ran 177 tests containing 932 assertions.
0 failures, 0 errors.
is the sort of summary I see from Cognitect's test-runner
Yep, me too: Ran 2 tests containing 3 assertions. 1 failures, 0 errors. + reported the actual failure, that's good enough for me.
worked like a charm @noisesmith. Thank you ๐
@kari.marttila Cognitect's test-runner is what we use at work. As for running a single test, I do that via my editor (because I never type into a REPL), and it can run all tests in the current namespace or just the test at the cursor.
Just looked at the source of the editor integration: it runs (clojure.test/test-vars [#'the-single-test])
so that would be how to run it manually in your REPL
there is a test-var too that's probably a little shorter
The difference between test-vars
and test-var
is that the former runs fixtures around the test(s) whereas the latter does not. I just changed my editor integration to use test-var
and tripped over this!
ah, I thought test-var did fixtures too
yeah, test-var
and both of those have the benefit (over just invoking the test var) of applying fixtures
Ok. Thanks!
Is it working hours there right now? ๐
It's noon for me. And 2pm for Alex.
Ok. Since my office hours ended 6 hours ago. This time I often do some personal Clojure studies. So, it's nice to know that there are Clojurians also this time reading this #beginners room. ๐
I'm usually here 9 am to 9 pm Pacific time on weekdays. Sometimes later. Weekends I'm mostly only around in the evenings Pacific. ๐
I'm trying to import some java classes into a little plaything and I'm getting an eval error, am I doing something wrong...?
(ns azure.core
(:import [com.microsoft.azure.servicebus TopicClient ReceiveMode]
[com.microsoft.azure.servicebus.primitives.ConnectionStringBuilder])
(:gen-class))
Syntax error macroexpanding clojure.core/ns at (core.clj:1:1).
((:import [com.microsoft.azure.servicebus TopicClient ReceiveMode] [com.microsoft.azure.ser
vicebus.primitives.ConnectionStringBuilder]) (:gen-class)) - failed: Extra input spec: :clo
jure.core.specs.alpha/ns-form
it feels like I'm not adhering to a spec? but looking at the ns doc, it's not clear.
Maybe you don't want vectors
I just figured out how to use test fixtures to start the app states related to my tests (Mount). Yihaa! ๐ I like these evenings. My kids are already adults so I get to do what ever I like and I like doing small Clojure projects and learning more Clojure and at the same time listen to old Jazz divas. Clojure provides these small happy moments when you get something working.
@dharrigan should have a space between primitves and ConnectionStringBuilder
Hi, I wanted to ask what is the most idiomatic way to create n
many different "square" components in a parent "row" component (using reagent). Each square takes a character prop. I was thinking something like this:
(defn row [{:keys [characters]}]
[:div (map #(-> [square {:character %1 :key %2} characters (range)])
as a small improvement you can use map-indexed
instead of explicitly adding range as an argument
Ah, thanks! By the way, I was also wondering if my use of ->
in the lambda the idiomatic way of returning a value from a lambda that does not result from a function call?
I would use #(vector square {:character %2 :key %} characters (range))
. I've never seen ->
used like that. That said, I don't find using ->
unreadable. It's just personal preference.
I'd just use (fn [c k] [...])
other possibilities include do
, and
, or
, identity
, doto
... - there are many ways to return the first arg of a one arg form, but all of them suffer from the problem of being nonsense in this context
they are correct but distracting to a reader
you'd need to flip %1 / %2 though
@dharrigan The reason you'll mostly see :import
with ( .. )
instead of [ .. ]
is that the first element is considered "special" -- a package name , followed by one or more class names -- in the same way that in regular code (foo bar quux)
interprets foo
as something "special" -- a function followed by one or more arguments. /cc @jmsul
Vectors "work" just fine in imports, but they don't convey the "specialness" of the first element.
Thanks @seancorfield for the clarification! ๐
fwiw, last time Stuart Sierra posted about using lists instead of vectors in import, Rich didn't buy that argument. he uses vectors for both these days (as do I)
although there are plenty of examples of both in core
Yeah, I know there's no consensus on it, but I find it a very handy mnemonic for remembering the specifics of the syntax.
(it's definitely one of those little language quirks that I wish had been baked in stone from day one, in one way or another -- only vectors for all parts of ns
or only parens for import
and only vectors for the rest... but ns
was always horribly permissive)
The difference between test-vars
and test-var
is that the former runs fixtures around the test(s) whereas the latter does not. I just changed my editor integration to use test-var
and tripped over this!
just wrote a simple spike in clojure of an azure service bus producer/consumer using the azure java library and clojure interop ๐
yeah, the java interop is remarkably good. though I floundered for quite a while before I realized that I had to require
a namespace before I could import
the records Iโd created.
usually, you shouldn't need to import record classes
if you're constructing them, it's better to use the ->Foo
or map->Foo
constructor functions that are automatically created (but you'll need to refer those vars)
Ah, Iโve seen them mentioned, but the texts Iโve read mostly focused on the (MyRecord. ...)
java constructor sugar.
It is considered bad practice to use the interop constructor for records: https://stuartsierra.com/2015/05/17/clojure-record-constructors
Thanks for the reference, @UDF11HLKC!
Any time!
(I should have just read @U064X3EF3โs book instead)
In the end, it ended up being over-engineering from my Scala experience. Now itโs just a map. ๐
better :)