This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-01
Channels
- # announcements (23)
- # babashka (66)
- # babashka-sci-dev (7)
- # beginners (24)
- # biff (2)
- # calva (19)
- # cider (10)
- # clj-kondo (12)
- # cljs-dev (3)
- # cljsrn (2)
- # clojure (37)
- # clojure-art (1)
- # clojure-europe (50)
- # clojure-gamedev (1)
- # clojure-nl (1)
- # clojure-norway (22)
- # clojure-uk (7)
- # clojurescript (6)
- # conjure (28)
- # cursive (19)
- # data-science (11)
- # fulcro (21)
- # holy-lambda (12)
- # honeysql (6)
- # hyperfiddle (2)
- # jobs (1)
- # lsp (5)
- # malli (4)
- # meander (3)
- # missionary (8)
- # nbb (5)
- # off-topic (39)
- # rdf (9)
- # reitit (1)
- # releases (1)
- # sci (21)
- # shadow-cljs (42)
- # specter (1)
- # xtdb (11)
(defn foo [{b :bar}]
{:baz b})
=> #'user/foo
(foo {:bar 1})
=> {:baz 1}
(foo [{:bar 1}])
=> {:baz nil}
(foo '({:bar 1})) ;; WAT
=> {:baz 1}
(foo '({:bar 1} {:bar 2}))
=> {:baz nil}
I kind of recall this being a consequence of the recent keyword args/map args changes
Looks like hiredman is right, it's probably this: https://github.com/clojure/clojure/commit/3c9307e27479d450e3f1cdf7903458b83ebf52d7
If you pass in a ISeq
of 1 element, it falls through to that bottom if
and the (first ~gmapseq)
is used.
I can't decide if this case was intended or not. It doesn't appear to be documented in the commit or in any link the commit adds.
Like many other things, the trailing arg is added “as if by conj”, which includes many things people are not very aware of
I’m curious what other things you've noticed people are unaware of, @U064X3EF3? As someone who teaches Clojure, this is an asymmetry I’ll have to be sure to explain. Are there others you'd suggest adding to a curriculum?
Also understanding the motivation would be helpful. I've been recommending use of plain old maps over keyword arguments for sometime. While keyword arguments might make an API feel more fluent, it makes modification more painful by taking away associative ops, and typically requires some validation of arguments that the compiler would catch with a regular hash map literal. Maybe this simplifies areas of clojure.core or codebases other people have worked on, and I've yet to realise the benefits? I'll take a look at the JIRA ticket again.
For anyone interested in better understanding like me… this is in the original announcement post: > To date, Clojure’s support for keyword arguments forces programmers to choose between creating APIs that better support people (accepting keyword args) or APIs that better support programs (by taking a map of those args). https://clojure.org/news/2021/03/18/apis-serving-people-and-programs
I think this is the motivation: > If a programmer wishes to write a function that takes key/value pairs, or a map, or key/value pairs followed by a map then they must write code to perform checks in the function on its varargs and perhaps wrap that into a custom macro. Hmm.
Maybe I'm only seeing the problems and the people who are experiencing the value aren't popping up in Slack.
Heya, not sure if this is the right channel: I was trying out https://clojure.org/guides/dev_startup_time in a project and encountered a problem I couldn't overcome myself. I was able to produce a minimal repro which has further details: https://github.com/bevuta/clojure-improved-dev-startup-time-repro - hope it makes sense 🙏
Hah, agreed
because there is a user.clj it is loaded right away before anything else the clojure runtime does
and it requires the foo namespace, so that is also loaded right away before anything else
Right but the guide goes out of its way to have a section about just this issue
Heh true
I think I also tried with bare deftype
and that worked fine, as well
Must be due to the codewalking during macro expansion in potemkin or so
and that cleverness results in the type not being properly aot compiled if it was already loaded
https://github.com/clj-commons/potemkin/blob/master/src/potemkin/types.clj#L292-L293
because as the docstring there says "won't evaluate if an equivalent ... already exists" you can't force it to aot by reloading
Aaah 💡
Cool, at least it's documented and in fact kind of a feature 😄
Thanks a lot!
I guess I'll look into getting rid of user.clj
then 🙂