Fork me on GitHub

Ah, so a third namespace that stands in front of the two implementation ones?


That sounds reasonable, thanks!

Ivan Koz03:05:43

i'm reading weird characters guide, and namespace syntax for map literals doesn't expand like in example. Why?

Ivan Koz03:05:11

maybe there is an option to change that behavior


check out (doc *print-namespace-maps*)


if you're in an nrepl based repl there's a problem with changing this though.


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


oh interesting. i'll need to read the source again. thanks again 🙂


I seem to recall the nrepl behavior changed in one of the more recent builds

Ivan Koz03:05:04

alex is correct they fixed it in 6.0 (set! *print-namespace-maps* false) works just fine

😎 1
Ivan Koz03:05:25

alter-var-root isn't however, but i probably doesn't understand how it works

Ivan Koz03:05:14

btw what will be proper way to set it in lein project?


the command above I think will work in latest lein repl


Does unquote mean anything outside of a quote?


The source is (def unquote), so I wonder if it's unbound until inside a quoting form?


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

👍 1

oh I'm wrong it moved - that's commented out in I am looking for where it is defined now


syntax quote checks isUnquote and UnquoteReader creates the object that would return true for that predicate

Tomasz Rojek08:05:08

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 nils. 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


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


there are any parameters to the refresh function that I'm missing?


fixed.. was the :aot problem..


refresh is from org.clojure/tools.namespace


Parallelism question: I have a program that iterates over a {} that contains the state of the program (à la: 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?

Yehonathan Sharvit14:05:49

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;a_bid=399d9d64 Please send me a direct message if you are interested with reviewing parts of the book

👍 3
🐣 1

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)


If you look at this repo, there are good examples:

Alex Whitt14:05:05

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.e., {juxt.edge/edge.system {:local/root "../edge.system"},

Alex Whitt14:05:47

I'm pretty sure :duct.core/includeis deprecated


Thanks for the info, I’ll take a look at those


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


so don't use code namespaces for keywords, which makes them much less brittle


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?


I recommend not using '::'


the docs for things like spec use it for concision, but for most code it makes things too brittle


Ok, interesting, thanks!


💯 agreed with hiredman. I’ve ended up regretting :: in the past


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

Marco Nicolodi18:05:29

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


the bug in your original was due to not having an initial value ("") for the reduce


for building strings I believe doing string/join on a collection is generally better than incrementally building it up via reduce

Marco Nicolodi21:05:37

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.

Marco Nicolodi19:05:38

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 [ TopicClient ReceiveMode]    


Syntax error macroexpanding clojure.core/ns at (core.clj:1:1).
((:import [ TopicClient ReceiveMode] [
vicebus.primitives.ConnectionStringBuilder]) (:gen-class)) - failed: Extra input spec: :clo


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.


Oh I tried with and without vectors


same thing


@dharrigan should have a space between primitves and ConnectionStringBuilder


have $1,000,000 worth of hugs


live and learn 🙂


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

bowie 1
👍 1

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)


I gotta say, the interop between clojure and java is wonderful!


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.


I didn’t need anything else from the ns


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.

Lennart Buit23:05:05

It is considered bad practice to use the interop constructor for records:

👍 1

Thanks for the reference, @UDF11HLKC!


(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. 🙂