Fork me on GitHub
#clerk
<
2023-05-12
>
Ben Sless08:05:46

How would you imagine a test viewer which displays test failure? three columns (or rows) of expected, actual, diff?

elken08:05:02

I like how devcards did it personally

Ben Sless09:05:24

I want to take advantage of the data structures view, does it do that?

Ben Sless09:05:18

I thought I'd group results by the testing context, too

elken09:05:29

It's very basic so no, but stylistic I like it šŸ˜„ Grouping sounds sensible

mkvlr14:05:56

been using the following fn on a project to sidestep sci when using clerk with a running cljs compiler, maybe others find it useful. cc @sritchie09

(defn cljs-render
  "Takes a symbol pointing at a cljs render function and constructs a
  viewer that looks up the `:render-fn` in the global `js`
  environment, without going through sci if `cljs.compiler/munge` can
  be resolved."
  [sym & args]
  (apply viewer/with-viewer
         {:transform-fn viewer/mark-presented
          :render-fn (if-let [cljs-munge (resolve 'cljs.compiler/munge)]
                       (symbol "js" (name (cljs-munge sym)))
                       sym)}
         args))

borkdude14:05:58

I guess you could also have

:evaluator :javascript
and then just insert a javascript expression in there like:
globalThis.my_awesome.function

mkvlr14:05:03

though I think I prefer the above as it will still use sci without the cljs compiler being available

Sam Ritchie14:05:47

Show-cljs was Mattā€™s take on this idea

borkdude14:05:07

It will use SCI in both cases, but in one case it just evaluates the expression to the global function, and in the other case, something that's available in a SCI ns

Sam Ritchie14:05:13

Define code in a cljc file and autogenerate the js function that the viewer invokes, with some reload logic

mkvlr14:05:16

my original problem was that the sci copy ns macro doesnā€™t pick up changes reliably

mkvlr14:05:14

@U04V15CAJ right, but itā€™s not going through sci to look up the function I mean

borkdude14:05:06

It still looks up a function through SCI, but just via the global JS context

mkvlr14:05:31

but not through sciā€™s lookup table

mkvlr14:05:41

you get what I mean šŸ™ƒ

borkdude14:05:41

if you use cherry/preserve-ns you can preserve those symbols globally btw

šŸ‘ 2
borkdude14:05:09

or if you add ^:export to the function

mkvlr14:05:47

@sritchie09 yep, though show-cljs & friends are a bunch of macros and this is one function šŸ™ƒ

Sam Ritchie14:05:28

Yeah fair, if you donā€™t want to see the viewer code which often you donā€™t this is better

mkvlr14:05:55

currently still requires a clerk show or reload to pick up changes so no great yet

Sam Ritchie15:05:20

šŸ‘ 2
šŸ˜ 6
šŸ’Æ 2
ā¤ļø 2
Sam Ritchie15:05:52

here is the no-macro version:

(with-state {:point [1 1]}
  (fn [!sym]
    (mafs
     (cartesian)
     (circle
      {:center [0 0]
       :radius (q (mafs.vec/mag (:point @~!sym)))})
     (movable-point
      {:atom !sym
       :path :point}))))

mkvlr16:05:49

looks good, does it work with the state coming from a clerk sync atom as well?

Sam Ritchie17:05:55

^::clerk/sync
(defonce server-state
  (atom [1 1]))

(mafs/mafs
 (mafs/cartesian)
 (mafs/circle
  {:center [0 0]
   :radius `(abs @server-state)})
 (mafs/movable-point
  {:atom `server-state}))

Sam Ritchie17:05:08

vs this

(with-let [point [1 1]]
  (mafs/mafs
   (mafs/cartesian)
   (mafs/circle
    {:center [0 0]
     :radius `(abs @~point)})
   (mafs/movable-point
    {:atom point})))

Sam Ritchie17:05:01

pretty similar! I had to provide the quoted symbol for the server-side one, and ditch the tilde inside the function I passed for radius

Sam Ritchie17:05:15

This is cool though:

`(abs @server-state)
this is using emmyā€™s abs via SCI

Sam Ritchie15:05:53

server-side rendering with clerkā€¦ the form at the top dynamically builds a viewer. thoughts? there are some sneaky quotes in there

Sam Ritchie18:05:16

okay here is the classic question for everyone. where should these functions live?? 1. they could live in mafs.cljs and offer a clj + clerk interface. but they require an Emmy dependency to serialize functions across. That would feel nice because there is no clj code now, so youā€™d gain a clj interface in the same project. But it would be very Clerk + Emmy-ish. Which is fine of course! 2. Or do the new dependencies imply that they go into emmy-viewers? The downside here is that MOST of the mafs clj-side is not Emmy-related. in some sense it doesnā€™t matter. but Iā€™ll follow the same route for leva, mathbox, mathlive, mafs, jsxgraph, so the pattern should feel appropriate. If users only had to ever think about mafs.core, mafs.coordinates etc, instead of emmy.mafs.coordinates... that is obviously better, since again Emmy is hiding behind the scenes here

Sam Ritchie18:05:30

@U07SQTAEM and for the eventual ā€œopen in mariaā€ weā€™ll want to make sure that this new API works on the cljs side too. so maybe that does imply a different library, since we want these functions to return reagent fragments

Sam Ritchie18:05:07

okay nice, so I need something new anyway

jackrusher18:05:07

@sritchie09 The Maria -> Clerk pipeline is oneway.

Sam Ritchie18:05:35

For sure, for nowā€¦ Iā€™m anticipating the other direction down the road

jackrusher18:05:36

I am actively hostile to that plan. The educational wiki thing of your heartā€™s desire is not Maria, though they may share many ideas and components.

Sam Ritchie18:05:11

Interesting, can you say more?

jackrusher18:05:31

The vision for Maria involves considerable simplicity. Itā€™s meant to introduce people to programming at all, from which I would prefer they graduate via the Maria->Clerk project exporter. The thing that allows hosting complex notebooks with arbitrary deps, at least in the near term, will be Garden. The thing further down that road, multiplayer/wiki/&c, is the thing you want.

Sam Ritchie18:05:36

given that I can open gists in Maria it didnā€™t seem too far off to imagine opening a projectā€™s file

Sam Ritchie18:05:55

@U07SQTAEM got it, that clarifies for sure

jackrusher18:05:12

If you think about the deps situation for Clerk projects (basically anything Clojure call pull in), it becomes clear why Maria canā€™t run them all in the browser. I understand that Emmy can do it, but most other libraries canā€™t.

mkvlr18:05:44

when mafs.cljs is consumed as a normal cljs lib, thereā€™s no issue with passing functions, is there?

Sam Ritchie18:05:50

thatā€™s right @U5H74UNSF. emmy helps there by allowing you to compile your fns to be fast, use automatic differentiation, etc, but everything works fine with cljs functions

Sam Ritchie18:05:05

@U5H74UNSF and in this srver-side model, if you didnā€™t have emmy you can] also pass a quoted function body like '(fn [x] (+ (Math/sin x) 10))

Sam Ritchie18:05:30

(mafs/mafs
 (mafs/cartesian)
 (mafs/of-x '(fn [x] (+ 2 (Math/sin x)))
            {:color (:green mafs/Theme)}))

mkvlr18:05:10

right, so that seems useful on its own then?

mkvlr18:05:35

though I guess Iā€™d care about that much later if I was you

Sam Ritchie18:05:47

yeah itā€™s useful for sure. I could definitely do emmy as an optional dependency, where if itā€™s available the function compilation code comes online

mkvlr18:05:48

like clerkā€™s render part is potentially also useful as its own library but Iā€™m happy I havenā€™t extracted it yet as things are still in flux

Sam Ritchie18:05:11

yeah, good call. note that this is possible and extract down the road

mkvlr18:05:55

so Iā€™d not worry too much about this and do whatever is best for your dev experience and focus on the integration with emmy part

āž• 2