Clojurians
#cljs-dev
<
2017-10-09
>

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

mhuebert12:10:12

has there been prior discussion (perhaps for planck and lumo) about allowing people to write macros for self-host in ordinary cljs namespaces, giving macro behaviour like in Clojure? eg.: https://www.maria.cloud/gist/65446d9a1cbe9ae23a7d04580917c1fc?eval=true

mfikes12:10:19

@mhuebert Yes. The "official" stance of the compiler is that it is doing nothing to prevent end-users from doing this, but it won't support it or guarantee that it will continue to work if users do that. It was covered in the penultimate point in the FAQ here https://github.com/clojure/clojurescript/wiki/Bootstrapped-ClojureScript-FAQ#with-bootstrapped-clojurescript-can-we-now-have-namespaces-that-mix-both-macros-and-functions

thheller12:10:36

@mfikes you have self-host experience: a :require in a macro namespace, does that resolve to a .cljs file or .clj file?

thheller12:10:32

most cases seem to resolve to a .cljc file which when gets compiled with :cljs conditionals

thheller12:10:07

but this file https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/js.clj#L11 is itself a .clj file and refers to another .clj file via :require

thheller12:10:47

I’m not sure if its supposed to resolve that or not

thheller12:10:16

given that the file also has a :require for [ :as io] which can’t work (and is not used anyways)

mfikes13:10:05

@thheller You are suppose to first see if a .cljs file exists, then a .cljc file. The rules are here https://github.com/clojure/clojurescript/blob/85b882b728984734793d635c923bfab0f71ba00f/src/main/cljs/cljs/js.cljs#L83-L87

mfikes13:10:09

I think you can't really say that you are in a macro namespace just by looking at the namespace itself. (It depends on how it is being consumed.)

thheller13:10:17

> If :macros is true resolution should only consider .clj or .cljc resources

thheller13:10:23

that answers my question, thx

thheller13:10:46

hmm well or not :stuck_out_tongue:

mfikes13:10:04

I think the js.clj file may only be compiled by JVM ClojureScript.

thheller13:10:40

yeah, my question is for the general case. just js.clj was the first example I found

thheller13:10:55

self-host still makes my head spin :wink:

mfikes13:10:01

Hah. Yes, when dealing with macros and self-host, it can get convoluted very quickly and it is a battle to keep the mental model simple.

mfikes13:10:09

When I first struggled with it, that's when the compilation stage nomenclature was introduced here https://clojurescript.org/about/differences#_macros and here https://clojurescript.org/about/differences#_namespaces in an attempt to provide some end-user digestible rules.

mfikes13:10:30

David found that term being used with Racket, IIRC, and we appropriated it.

thheller13:10:44

so :require in the compilation stage then resolves to .clj files if I understand everything correctly

mhuebert13:10:49

@mfikes thanks for the pointer. So the issue is that if we added support for clojure-style macros in self-host, they wouldn't be compilable with existing building tools / jvm compiler

mfikes14:10:30

@mfikes Exactly. The intent is to essentially avoid a fork between JVM and self-host codebases.

mhuebert14:10:01

@mfikes could build tools be upgraded to support this?

mhuebert14:10:20

"must use at least version X of build tool to use macros in ClojureScript namespaces" would be something less than a fork I think

mfikes14:10:53

@mhuebert Not clear what that might entail or mean. The issue is simply that if you have a .cljs file that defines and uses its own macros then it is relegated to (modified) self-host essentially.

mhuebert16:10:39

@mfikes I guess a build tool would have to use a self-hosted compiler in a JS environment to do the compiling, in order to support this