sci

borkdude 2023-03-07T10:59:31.835939Z

2023-03-07T11:26:45.156169Z

@borkdude I now have a macro like this working:

(defmacro sci-macro [form]
  (if (:ns &env)
    (let [[_defmacro name & body] form
          [doc body] (if (string? (first body))
                       [(first body) (rest body)]
                       [nil body])
          arities (if (vector? (first body)) (list body) body)
          arities (map (fn [[argv & body]] (list* (into '[&form &env] argv) body)) arities)]
      `(defn ~(vary-meta name assoc :sci/macro true)
         ~@(when doc [doc])
         ~@arities))
    form))
usage is
(sci-macro 
  (defmacro foo [a] ...))
when compiling for cljs, it emits a defn with :sci/macro metadata and &form &env prepended to all the argument vectors. so I can then do a straightforward sci/copy-ns on that namespace. At least I have tested it with Maria (so, cljs sci target)

2023-03-07T11:27:36.441749Z

with this, there’s no need to pull out the implementation at all (except when that’s desired for other reasons)

borkdude 2023-03-07T11:41:50.825239Z

@mhuebert that's very exciting! finally!

borkdude 2023-03-07T11:44:48.533429Z

@mhuebert but when compiling for CLJS, it doesn't ever need to be defmacro for the JVM CLJS compiler? I'm a bit confused :)

2023-03-07T11:45:22.097259Z

correct, the inner defmacro is removed (becomes a defn) when compiling for cljs

2023-03-07T11:45:43.366239Z

but it has the :sci/macro metadata added, so that when sci copies the namespace it becomes a macro

2023-03-07T11:46:52.920069Z

the (:ns &env) is true when the target is cljs. normally when the target is cljs the macro disappears

2023-03-07T11:47:15.734929Z

oh

2023-03-07T11:47:26.999969Z

maybe I am mistaken after all

2023-03-07T11:47:38.173049Z

hmm

2023-03-07T11:48:55.810919Z

i think: when sci-macro expands for the JVM cljs compiler it will still emit defmacro

2023-03-07T11:49:21.400149Z

this will break in selfhost but I am currently not trying to target that

borkdude 2023-03-07T11:51:20.390649Z

as long as it works for you :)

borkdude 2023-03-07T11:55:45.601799Z

with another layer of macrovich it'd probably work for all ;)

Matthew Downey 2023-03-07T01:49:47.371429Z

I'm writing a chrome extension to eval text with SCI and show the results in a little popup. I'm hoping to render return results as react components, and then have a user.clj for the extension to define helpers to load whatever is useful into the browser, e.g. a clock or a real-time view of some data source. Not pragmatic, but fun, and I'm enjoying SCI so far!

1
🎉 1
borkdude 2023-03-07T09:05:29.453269Z

Awesome :)

respatialized 2023-03-07T14:17:09.746339Z

"view source" but returns the react/reagent components in the page as data structures

respatialized 2023-03-07T14:18:14.565229Z

(e.g. I'm imagining how it might be possible to mix your in-page evaluations with data already provided by the page)

Matthew Downey 2023-03-07T14:21:05.573849Z

That'd be cool! I wonder if there's enough information in the minified source for something like ChatGPT to work backwards to a ClojureScript + Reagent + Hiccup representation of a "normal" JS react component from out in the wild.

respatialized 2023-03-07T15:29:20.892609Z

I forgot about the “compiled” nature of JSX, shame that we would have to resort to such shaky methods just to understand the code that our browsers are executing