Fork me on GitHub
#beginners
<
2019-05-16
>
jstaab00:05:35

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

jstaab00:05:04

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? https://gyazo.com/54b9207c6ae4b5d4c35de9da822f25cb.png

Ivan Koz03:05:11

maybe there is an option to change that behavior

dpsutton03:05:14

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

dpsutton03:05:03

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

dpsutton03:05:37

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

Alex Miller (Clojure team)03:05:22

I think that may have actually changed

dpsutton03:05:40

oh interesting. i'll need to read the source again. thanks again ๐Ÿ™‚

Alex Miller (Clojure team)03:05:49

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

๐Ÿ˜Ž 4
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?

Alex Miller (Clojure team)04:05:46

the command above I think will work in latest lein repl

penryu06:05:53

Does unquote mean anything outside of a quote?

penryu06:05:06

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

noisesmith17:05:29

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

noisesmith17:05:20

the special form for ` is where all the unquote logic lives, and all the special forms are in the java code in the compiler

๐Ÿ‘ 4
noisesmith17:05:39

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

noisesmith17:05:11

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.

jumar11:05:55

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

bartuka10:05:08

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

bartuka10:05:20

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

bartuka10:05:41

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

bartuka11:05:05

fixed.. was the :aot problem..

bartuka10:05:57

refresh is from org.clojure/tools.namespace

tabidots10:05:58

Parallelism question: I have a program that iterates 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?

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 https://www.manning.com/books/get-programming-with-clojure?a_aid=viebel&amp;a_bid=399d9d64 Please send me a direct message if you are interested with reviewing parts of the book

๐Ÿ‘ 12
๐Ÿฃ 4
Kevin14:05:36

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)

dharrigan14:05:11

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

dharrigan14:05:06

i.e., {juxt.edge/edge.system {:local/root "../edge.system"},

Alex Whitt14:05:47

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

Kevin14:05:52

Thanks for the info, Iโ€™ll take a look at those

eskemojoe00718:05:24

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.

eskemojoe00718:05:27

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"

noisesmith18:05:05

the 500 error should have had an associated stack trace and exception

eskemojoe00718:05:42

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

noisesmith18:05:18

that's in the browser I assume

noisesmith18:05:26

there should be something else from the app

noisesmith18:05:14

it could be that you have a badly configured logger or an over eager try/catch preventing you from seeing the issue

noisesmith18:05:22

what's happening inside docker?

eskemojoe00718:05:43

Normally I look at the docker logs, and I am not getting any info there.

eskemojoe00718:05:54

Let me run it in -it mode

jstaab18:05:51

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)

eskemojoe00718:05:43

Hmm @noisesmith I'm not able to find any logs...any clue how>

noisesmith18:05:43

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

noisesmith18:05:43

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

eskemojoe00718:05:02

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.

eskemojoe00718:05:40

The table isn't there so It doesn't look like its migrating.

hiredman18:05:23

the first thing to understand is keyword namespaces are not connected to code namespaces

hiredman18:05:03

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

hiredman18:05:39

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

hiredman18:05:19

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

jstaab18:05:21

That makes tons of sense, but ::keywords are auto-namespace based on where they're defined, what's the use case for those?

hiredman18:05:40

I recommend not using '::'

hiredman18:05:24

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

jstaab18:05:49

Ok, interesting, thanks!

lilactown18:05:39

๐Ÿ’ฏ agreed with hiredman. Iโ€™ve ended up regretting :: in the past

lilactown18:05:29

until we can easily alias symbols for use with :: without other effects, it makes things far too brittle

andy.fingerhut18:05:28

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 ?

andy.fingerhut18:05:52

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?

lilactown21:05:07

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

lilactown21:05:46

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

yuhan19:05:21

(str/join \newline
  (map #(str/join " " (cons %1 %2))
    (cons " " (range))
    (cons (range 3) game)))

yuhan19:05:35

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

yuhan19:05:09

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

Kari Marttila18:05:49

Is it possible to call one specific deftest in REPL?

noisesmith18:05:44

(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

noisesmith18:05:53

it's a lot messier than what you started with

Kari Marttila18:05:23

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

seancorfield19:05:06

Ran 177 tests containing 932 assertions.
0 failures, 0 errors.
is the sort of summary I see from Cognitect's test-runner

Kari Marttila19:05:27

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 ๐Ÿ™‚

seancorfield19:05:22

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

seancorfield19:05:43

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

Alex Miller (Clojure team)19:05:42

there is a test-var too that's probably a little shorter

seancorfield21:05:34

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!

Alex Miller (Clojure team)22:05:51

ah, I thought test-var did fixtures too

Alex Miller (Clojure team)19:05:48

and both of those have the benefit (over just invoking the test var) of applying fixtures

Kari Marttila19:05:01

Is it working hours there right now? ๐Ÿ™‚

seancorfield19:05:16

It's noon for me. And 2pm for Alex.

Kari Marttila19:05:20

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. ๐Ÿ™‚

seancorfield19:05:37

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. ๐Ÿ™‚

dharrigan19:05:15

I'm trying to import some java classes into a little plaything and I'm getting an eval error, am I doing something wrong...?

dharrigan19:05:32

(ns azure.core    
  (:import [com.microsoft.azure.servicebus TopicClient ReceiveMode]    
   [com.microsoft.azure.servicebus.primitives.ConnectionStringBuilder])                
  (:gen-class))    

dharrigan19:05:45

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

dharrigan19:05:06

it feels like I'm not adhering to a spec? but looking at the ns doc, it's not clear.

eval-on-point19:05:22

Maybe you don't want vectors

Kari Marttila19:05:36

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.

dharrigan19:05:54

Oh I tried with and without vectors

dharrigan19:05:55

same thing

4
markmarkmark19:05:18

@dharrigan should have a space between primitves and ConnectionStringBuilder

dharrigan19:05:49

have $1,000,000 worth of hugs

dharrigan19:05:07

live and learn ๐Ÿ™‚

dharrigan19:05:41

thanks ๐Ÿ™‚

Jay19:05:49

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

noisesmith20:05:51

as a small improvement you can use map-indexed instead of explicitly adding range as an argument

Jay21:05:28

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?

jaihindhreddy13:05:40

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.

noisesmith17:05:47

I'd just use (fn [c k] [...])

noisesmith17:05:12

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

noisesmith17:05:30

they are correct but distracting to a reader

noisesmith20:05:06

you'd need to flip %1 / %2 though

seancorfield20:05:35

@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 4
๐Ÿ‘ 4
seancorfield20:05:59

Vectors "work" just fine in imports, but they don't convey the "specialness" of the first element.

dharrigan20:05:17

Thanks @seancorfield for the clarification! ๐Ÿ™‚

Alex Miller (Clojure team)20:05:51

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)

Alex Miller (Clojure team)20:05:20

although there are plenty of examples of both in core

seancorfield21:05:46

Yeah, I know there's no consensus on it, but I find it a very handy mnemonic for remembering the specifics of the syntax.

seancorfield21:05:12

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

seancorfield21:05:34

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!

dharrigan21:05:53

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

dharrigan21:05:29

just wrote a simple spike in clojure of an azure service bus producer/consumer using the azure java library and clojure interop ๐Ÿ™‚

penryu23:05:07

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.

penryu23:05:23

I didnโ€™t need anything else from the ns

Alex Miller (Clojure team)23:05:24

usually, you shouldn't need to import record classes

Alex Miller (Clojure team)23:05:13

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)

penryu23:05:42

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: https://stuartsierra.com/2015/05/17/clojure-record-constructors

๐Ÿ‘ 4
penryu23:05:59

Thanks for the reference, @UDF11HLKC!

penryu23:05:19

(I should have just read @U064X3EF3โ€™s book instead)

penryu23:05:30

In the end, it ended up being over-engineering from my Scala experience. Now itโ€™s just a map. ๐Ÿ™‚