Fork me on GitHub
David Pham09:12:58

Hello everyone :) I would be interested to know if there exist a guide to show how to share local lib in CLJS?


hello, I mostly got down the basics of clojure, but I'm a bit lost at how to continue. I don't have many ideas for fun projects, but if I do come up with one I usually can't really implement it. any tips?


@clojuregeek thanks very much, I'll have a look!


Hi. A Java class method won't accept a reified Java interface on account of (it would seem) the interface having type "reify" and thus not having the type of the Java interface. What can I do to solve this?


I'm trying to come up with a way to check which number in a list my number is closest to. like if I have 3.54 and my list consists of (2 4 6 etc.) how can I find out it's closest to 4 in a functional way? I keep coming up with loops which seems too imperative


map distance of 3.54 to every element in list, keep the minimum?


@shin you can do something like the folowing:

(let [x 3.54
      values [2 4 6]
      distance (fn [z] (.abs js/Math (- z x)))]
  (->> values
       (map (juxt identity distance))
       (sort-by second)))


(first (sort-by #(abs (- 3.54 %)) [1 2 3 4]))


you could also use a min-key application

Lennart Buit16:12:16

dpsutton’s impl is using the JS runtime, be wary of that ^^


(defn abs [n] (max n (- n))) is what i used


yes thanks. i had a cljs repl up right now

Lennart Buit16:12:19

not sure what the spread js/jvm users is actually


Using (Math/abs ,,,) works in both clj and cljs

parens 4
Lennart Buit16:12:46

yeah, but (.abs js/Math …) certainly doesn’t 😛


min-key looks a lot better for this (apply min-key #(Math/abs (- % 3.54)) [-3 1 4])

Lennart Buit16:12:15

In core async, there is put! and >!! right, one being “fire and forget”, the other being blocking if I understand correctly. What would be a downside of using put! except for the obvious “not knowing whether the message was processed”?

Alex Miller (Clojure team)16:12:57

none - put! is considered lower level (>!! is built on it) but either is fine

Lennart Buit16:12:44

Right, so if I want “fire and forget”, put! is also fine. Thanks!

Alex Miller (Clojure team)16:12:27

yep, that’s what it’s for


if i do lein run, can i connect to it with lein repl :connect with the correct settings? I have a .nrepl-port file, but i'm getting Connection refused - something in the project.clj ?


lein run does not start an nREPL server (unless your app starts one explicitly).


Are you sure? I’m pretty sure it does


Nevermind. I confused lein run with lein repl. My mistake! 😞


lein run doesn't run an nrepl server, it just runs your code


is there a way to attach to the running process with a repl? (or, in dev, how would i start the repl server?)


basically, i want my process to be running in a container off in my "bunch of docker container servers" stuff, and if needed, connect up a repl and operate via that within the context of the running app


(does that even make sense?)


@hoopes Another approach to consider is to provide JVM options when starting your process that tell Clojure itself to start a Socket REPL on a specific port, and then you can either connect via telnet/netcat or use Unravel to connect (which provides a much nicer REPL experience).


It depends whether you actually need nREPL in the mix.


awesome - thanks @trailcapital and @seancorfield - much appreciated


I wish the socket REPL had a little bit wider support. I do almost all of my development with apps deployed in docker - then use vim-fireplace to connect to the open nREPL, which doesn't support socket REPL. Maybe one day!


The Unrepl folks are working with the nREPL folks now so that may well become a reality -- I believe their goal is to allow an nREPL client to automatically upgrade a Socket REPL to nREPL...

👍 4

hello, i have a question regarding namespaced hash-maps. looks like the namespace for a hash-map is only applied to the top level keys not applied to the child hash-maps.


an example: (get-in #:foo{:bar :eh} [:foo/bar])


(get-in #:foo{:bar :eh} [:bar]) ;; nil


goo so far


(get-in #:foo{:bar {:car :eh}} [:foo/bar :foo/car]) ;; nil


(get-in #:foo{:bar {:car :eh}} [:foo/bar :car]) ;; :eh


are the keys for a nested hash-map not namespaced on purpose or am i not using this feature correctly?

Alex Miller (Clojure team)22:12:54

just want to step back a second to make an important point. When you say “namespace for a hash-map”, hash maps do not have a namespace - this is syntax only. #:foo{:bar :eh} is the identical value to {:foo/bar :eh} - they are just two different syntaxes.

Alex Miller (Clojure team)22:12:58

but yes, the syntax only extends to the top level keys in the map


ah i see. thank you, i was missing the point "hash maps do not have a namespace"


i want to do POSTs from my CLJS app...


What's the best cure for my ailment?


Hi i has another question that is n00b worthy


{:status 200 :session (assoc session :uid user-id)} ... I want to associate more than just :uid user-id ... for example, i'd like to add :uid user-id and :auth-key $yag and :login-time 7164516721 .... Can I simply assoc the whole map?


You can make a single call to assoc that takes an arbitrary map, and one new key-value pair to add to it, or a list of several new key-value pairs to add.


If you have two arbitrary maps you want to combine in some way, merge or merge-with are worth looking into


I spoke imprecisely there - assoc does not take a list, but you can give multiple arguments with multiple key1, value1, key2, value2, etc. arguments


Oh that's just as good


Thank you. I was getting wrong number of args


maybe merge is the right move

Alex Miller (Clojure team)23:12:05

If any of those are conditional, then cond-> is great for that