Fork me on GitHub
#beginners
<
2020-06-08
>
adam13:06:04

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

dpsutton13:06:02

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

adam13:06:52

Oh that's cool! Thanks.

dpsutton13:06:18

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

capybaras14:06:18

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)

dpsutton15:06:08

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?

dpsutton15:06:41

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]
  `(do
     (map #(println % ": " ~%) '~args)))
That errors with an "Unable to resolve symbol" on the ~%.

alexmiller16:06:09

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

alexmiller16:06:06

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

alexmiller16:06:48

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

alexmiller16:06:20

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]
  `(do
     (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

alexmiller17:06:31

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?

alexmiller17:06:09

no, you don't want that to be qualified

alexmiller17:06:44

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?

alexmiller20:06:04

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

alexmiller20:06:11

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?

alexmiller20:06:03

what are you missing about peek?

alexmiller20:06:25

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

phronmophobic20:06:19

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

alexmiller20:06:21

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.

alexmiller20:06:24

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

๐Ÿค™ 1
alexmiller20:06:38

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