Fork me on GitHub
#cljs-dev
<
2019-02-21
>
borkdude11:02:40

Maybe someone here can explain why a self-referring require-macros is necessary in .cljc? I knew how to fix the issue, but I can’t explain it properly. I just know it works and therefore I’ve always done this in .cljc. https://dev.clojure.org/jira/browse/TCHECK-154?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&amp;focusedCommentId=51375#comment-51375 (cc @gfredericks)

borkdude11:02:17

I think it has something to do with macro inference, so you don’t need a require-macros when referring to the namespace?

mhuebert11:02:59

my mental model is that the compiler makes 2 completely separate passes, one in cljs and one in clj, and neither pass “knows” about the other by default, so the cljs pass needs to be instructed to require the macros that were read in the clj pass if it wants to use them.

thheller11:02:29

:require-macros tells the CLJS compiler to require the macro namespace. otherwise the macros are not loaded and won't be expanded

thheller11:02:17

since the defmacro is visible in :cljs and not elided it will just be called as a function

borkdude11:02:23

alright. feel free to post these words in the JIRA issue 🙂

borkdude11:02:12

I’ll just copy your replies

mhuebert11:02:59

that behaviour of defmacro working like a function can be surprising. one can use @cgrand’s macrovich utils to write a defmacro that avoids it:

(core/defmacro defmacro
  "Like defmacro, but only evaluated at macro-definition time"
  [& body]
  `(net.cgrand.macrovich/deftime
    (core/defmacro [email protected])))

thheller11:02:37

@borkdude I'll post a proper reply

borkdude11:02:04

@mhuebert yeah, I’m using those macros all the time

borkdude11:02:37

I’ve been bitten by a macro working like a function more then once and I believe it’s only there for self-hosted?

borkdude11:02:18

I mean, why not just ignore the macro definition in the CLJS stage when not in self-hosted mode?

mhuebert11:02:37

hmm. maybe related to self-hosted for some low-level reason, but it can bite you there the same way. the ^defmacro replacement above was written while trying to get macros to work “seamlessly” in Maria, where it’s easy to hit the macro-as-fn problem

thheller11:02:45

shadow-cljs filters defmacro 😉

mhuebert11:02:59

I think I set that problem aside, didn’t see a way to make macros work nicely there without introducing too much inconsistency with normal cljs

mhuebert11:02:11

@thheller nice, is that new?

thheller11:02:56

11 months ago .. so not that new

borkdude12:02:28

@thheller a patch for upstream would be cool 🙂

thheller12:02:34

don't know how, not familiar with how the default compiler works anymore when it comes to self-hosted stuff

thheller12:02:16

probably should have a discussion about it first too. there might be a reason its not done by default that I'm not aware of

borkdude13:02:28

Using generative testing I think I’ve found a bug in CLJS set/union:

$ clj -A:test -m cljs.main -re node
ClojureScript 1.10.520
cljs.user=> (require '[clojure.set :as set])
nil
cljs.user=> (set/union #{} nil)
#{} ;; <- empty set, correct
cljs.user=> (set/union #{} nil nil)
() ;;<- not a set!
cljs.user=> (set/union #{} nil nil nil)
() ;; <- not a set!

borkdude13:02:36

I’ll make an issue about it

mfikes13:02:17

I thought the set functions only take sets

borkdude14:02:20

I can reduce it down to the difference of (reduce into nil (list #{})) in CLJS and CLJ. In CLJS it’s () and in CLJ it’s nil

borkdude14:02:08

The specs in speculative take nilable sets and also return nil or a set. I’ll read back why that decision was made.

borkdude14:02:08

@mfikes > alexmiller [5:57 PM] > I think right now I would treat both inputs and output as nilable > as existing code may be relying on the behavior of those things > nils are often used interchangeably with empty collections. it seems unlikely to me that there is not some code relying on this either for input or output https://github.com/borkdude/speculative/issues/70

borkdude14:02:43

@dnolen Pre-screening/vetting would be nice before I write a patch for this: https://dev.clojure.org/jira/browse/CLJS-3054