Fork me on GitHub

Is there a shortcut for getting a value from a string indexed map? ("key" m) doesn't work like keyword indexed map. Is it only (get m "key")?


maps are invocable: ({"a" "b"} "a") -> "b"


Oh that's cool! Thanks.


its simply what should happen if a keyword is in the first position (:foo ...) It could either throw an error as not a function, or it look up


Need to collab with a team that has never seen clojure. Best resource to get them started so they can at least read and understand the code? (versus developing new features)


if you post this on reddit, i bet you will get some answers. i think yogthos is active there and he has lots of experience ramping up new-to-clojure coworkers

๐Ÿ‘ 2
Jim Newton15:06:24

Is there a lien channel on clojurians?


channels auto complete for me. i can hit cmd-k lein and it shows me the matching channels

Jim Newton15:06:17

apparently there are many more channels than the ones appearing in my reader.

Andrew Nichols16:06:40

Has anyone seen a version of the animal guessing game written in Clojure?

Eric Ihli16:06:49

How would I do what it looks like I intend the following macro to do?

(defmacro pprint
  [& args]
     (map #(println % ": " ~%) '~args)))
That errors with an "Unable to resolve symbol" on the ~%.


I think you'd want ~'% in both places, but maybe better to use the fn form


and you probably don't want a ' on '~args


and in general, I'd try to avoid map for side effects - run! prob preferred here


are you trying to print both the name of the arg and the value of it?

Eric Ihli16:06:27

Yes. Didn't know about run!. Thanks.

Eric Ihli17:06:18

What do you mean about having ~'% in both places? How would that print 2 different things?

Eric Ihli17:06:26

Also, without the ' on '~args, it expands to (arg1 arg2) and blows up because it tries to call the function arg1 rather than treating it like a list of data to iterate over.

Eric Ihli17:06:00

I thought this would be closer, but it still doesn't work. It expands to something that looks correct.

(defmacro pprint
  [& args]
     (run! #(println % ": " (eval %)) '~args)))

(let [a 1 b 2]
  (macroexpand `(pprint a b)))
;; => (do
;;     (clojure.core/run!
;;      (fn*
;;       [p1__31102__31103__auto__]
;;       (clojure.core/println
;;        p1__31102__31103__auto__
;;        ": "
;;        (clojure.core/eval p1__31102__31103__auto__)))
;;      '(ezmonic.moniq/a ezmonic.moniq/b)))

(let [a 1 b 2]
  (pprint a b))
;; => 1. Caused by java.lang.RuntimeException
;;    Unable to resolve symbol: a in this context


you need to think more carefully about what happens at compile time vs runtime

Eric Ihli17:06:43

Is the runtime a in (let [a 1] ,,,) not equal to ezmonic.moniq/a?


no, you don't want that to be qualified


at compile time you can capture the local names of the symbols (~args), and you want to emit code with those (unqualified) symbols and that then evaluates those symbols at runtime

Kenneth Cheung17:06:39

I think you can use Unquote splicing here

[[email protected]]

Jim Newton19:06:23

It looks to me like the repl does not call print-method to print records. Could this be the case? Is that a bug?


there no special exclusion of anything like that so I doubt that is the actual story


maybe unroll to why you say that

Eric Ihli20:06:35

(peek (map identity (range 20))) That raises. Can't peek into a lazy seq, right? Why does (peek (doall (map identity (range 20)))) also fail for the same reason? What am I missing about doall?


what are you missing about peek?


peek works on instances of IPersistentStack, which are lists, vectors, and queues (not seqs)


doall will force evaluation, but it wonโ€™t convert a seq into something besides a seq


if you just want to look at the first thing in a seq, use first

Eric Ihli20:06:15

Ah. I see. I thought the problem was that the lazy thing wasn't realized. Not that realizing a lazy seq still gave you a seq and peek didn'k work on seqs.


reading that back, I meant that question with a ๐Ÿ˜€ not sure if that came across!

๐Ÿค™ 1

generally, I would not use peek/pop unless you're actually using a collection as a stack