This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-25
Channels
- # announcements (2)
- # beginners (30)
- # biff (12)
- # calva (2)
- # cider (62)
- # clerk (18)
- # clj-commons (20)
- # clojure (9)
- # clojure-europe (6)
- # clojure-switzerland (1)
- # core-logic (6)
- # datomic (4)
- # events (3)
- # fulcro (1)
- # membrane (15)
- # off-topic (16)
- # portal (24)
- # practicalli (2)
- # releases (1)
- # rewrite-clj (45)
- # shadow-cljs (14)
- # tools-build (1)
- # xtdb (4)
why does map behave differently with a list than a vector?
(def listofmaps [{:name "Dave" :age 30} {:name "Jill" :age 28}])
#'user/listofmaps
(map :name listofmaps)
("Dave" "Jill")
user=>
vs:
(def listofmaps ({:name "Dave" :age 30} {:name "Jill" :age 28}))
#'user/listofmaps
(map :name listofmaps)
()
user=>
@U03KMPFU4TH The second listofmaps
is not a list of maps, but a function call of the first map on the second map
k no wonder I was confused
A trick I often use is to look at intermediate values:
user=> [{:name "Dave" :age 30} {:name "Jill" :age 28}]
[{:name "Dave", :age 30} {:name "Jill", :age 28}]
user=> ({:name "Dave" :age 30} {:name "Jill" :age 28})
nil
found some very odd behaviour with anonymous functions macro:
((fn [a b] [a b]) "foo" "bar")
["foo" "bar"]
(#([%1 %2]) "foo" "bar")
Execution error (ArityException) at user/eval316$fn (REPL:1).
Wrong number of args (0) passed to: clojure.lang.PersistentVector
user=>
ah this "gotcha" is actually listed on the docs https://clojure.org/guides/learn/functions#_gotcha
👋 2
👍 4