This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-02
Channels
- # adventofcode (6)
- # announcements (6)
- # babashka (21)
- # babashka-sci-dev (18)
- # biff (6)
- # clara (4)
- # clj-commons (2)
- # clj-kondo (7)
- # cljdoc (4)
- # clojure (9)
- # clojure-berlin (8)
- # clojure-europe (23)
- # clojure-gamedev (3)
- # clojure-indonesia (1)
- # clojure-nl (1)
- # clojure-norway (10)
- # clojure-poland (1)
- # clojurescript (27)
- # community-development (1)
- # conjure (32)
- # etaoin (6)
- # events (20)
- # fulcro (5)
- # graalvm (1)
- # helix (19)
- # hyperfiddle (14)
- # introduce-yourself (2)
- # music (1)
- # nbb (24)
- # off-topic (37)
- # pathom (2)
- # polylith (14)
- # reagent (11)
- # releases (1)
- # remote-jobs (1)
- # reveal (22)
- # shadow-cljs (16)
- # sql (3)
- # squint (11)
- # test-check (2)
- # xtdb (36)
Is there any reason why #(@foo)
and #(deref foo)
wouldn’t be equivalent?
nice catch! thanks
always let the reader expand those:
cljs.user=> '#(@foo)
(fn* [] ((clojure.core/deref foo)))
cljs.user=> '#(deref foo)
(fn* [] (deref foo))
i think noisesmith first showed me that@U11BV7MTK interesting! thank you
looks like it also works for var:
user=> (def foo 1)
#'foo
user=> '#'foo
(var foo)
user=> (quote #'foo)
(var foo)
are there any other reader forms that we can be observe being desugared like this?
anything that gets expanded by the reader presumably. But some things will have the same print representation like #{}
ah, quoting itself ''foo
=> (quote foo)
but I think that’s the last one
prometheus=> `(inc)
(clojure.core/inc)
prometheus=> '`(inc)
(clojure.core/seq (clojure.core/concat (clojure.core/list 'clojure.core/inc)))
hmm, what’s going on there?
ah I see, wow
thanks again, update the cljs docs with some desugar examples: https://github.com/cljs/api/commit/dd197d169a39a22e58b66939be4d814fd4475c09
I don't suppose there is an equivalent of clojure.core/extend
in cljs, is there? 😞
But there's an issue for it: https://clojure.atlassian.net/browse/CLJS-2786
Oh, interesting. Advanced compilation... yeah that's a thing.
Ok more direct follow-up, does anyone know of a programmatic way to do extend-type
or extend-protocol
? i.e., a hypothetical
(extend-types
[Orange Strawberry Bananna]
ISomeFuncManager
(-some-func1 [this a] (* a a))
Inst
(inst-ms* [this] (inst-ms (java.time.Instant/now))))
?Yeah. This macro covers the sitauation I just described:
(defmacro extend-types [types & specs]
(let [impls (#'clojure.core/parse-impls specs)]
(list* 'do
(map
(fn [protocol]
(let [spec (get impls protocol)
next-specs (list* 'extend-protocol protocol
(mapcat
(fn [type]
(conj spec type))
types))]
next-specs))
(keys impls)))))
however, it does not work for this situation:
(let [fruit [Orange Strawberry Bananna]]
(extend-types fruit
ISomeFuncManager
{-some-func1 (fn [this a] (* a a))}
Inst
#(inst-ms (java.time.Instant/now))))
and that's a huge bummerand I think bottom line it's a consequence of the fact that extend-protocol
and extend-type
are macros and you can't put in a variable for the classname
Another way to put it, this won't work:
(defmacro extend-types [types & specs]
(let [specs# (#'clojure.core/parse-impls specs)]
`(for [~'t ~types]
(extend-type ~'t ~specs#))))
because this won't work either:
(let [fruit [Orange Strawberry Bananna]]
(doseq [fruit fruits]
(extend-type fruit
ISomeFuncManager
{-some-func1 (fn [this a] (* a a))}
Inst
#(inst-ms (java.time.Instant/now)))))
It's easy enough to do in Clojure using extend
, but I haven't found an equivalent way in cljs