matrix

awb99 2025-01-13T06:04:53.856099Z

Hi @hiskennyness I have encountered a issue that you with your algebra background perhaps know how to solve (with clojure macros or otherwise). So let me explain. The beauty of react is that the rendering part of a ui component is just dealing with values. Example: (div (p (str "Hello" user)))

kennytilton 2025-01-13T06:06:08.861559Z

ok. and? 🙂

kennytilton 2025-01-13T06:09:40.845699Z

You might want to change your default to not to send on return. It is less handy in some ways, but it avoids accidental sends. hth!

kennytilton 2025-01-13T06:16:26.506339Z

Are you watching the Blue Origin launch? https://www.blueorigin.com/missions/ng-1

kennytilton 2025-01-13T06:17:02.506979Z

Just for context, what problem are we solving?

awb99 2025-01-13T06:06:55.767329Z

No the part that you have solved so far is extract the hierarchy of elements (div Kids are [p], p Kids is [(str "hello" user)])

awb99 2025-01-13T06:07:19.969309Z

A normal ui function would be:

awb99 2025-01-13T06:08:51.443669Z

(defn user-greeting [user-id] ; non ui part (let [user (get-user user-id)] ; ui part (div (p (str "Hello " user))))

awb99 2025-01-13T06:09:57.822609Z

Now if we by convencion define that all input of a dom element is dynamic (a cell / formula)

awb99 2025-01-13T06:10:32.575959Z

And the convention is that all symbols ending with # are formulas.

awb99 2025-01-13T06:10:50.101319Z

This means such ui functions need to be a macro too.

awb99 2025-01-13T06:11:40.074089Z

Then it should be possible to infer the type of all variables, and wrap necessary conversion automatically.

awb99 2025-01-13T06:11:53.012659Z

Example

awb99 2025-01-13T06:13:01.239819Z

(def-ui [user#] (div (p (str "Hello " user#))))

awb99 2025-01-13T06:13:56.921989Z

In this example it is clear that (str "Hello " user#) is a formula depending on a formula; and needs to ve wrapped.

awb99 2025-01-13T06:14:58.187659Z

This type of transformation can only happen on binding names and not of the value passed in, because at macro expansion this information is not known.

awb99 2025-01-13T06:15:16.481699Z

I could go more complex:

awb99 2025-01-13T06:17:04.371029Z

(def-ui [user#] (if (:male user#) (p (str "Hello mr. " (:name user#))) (p (str "Hello mrs." (:name user#)))))

awb99 2025-01-13T06:17:46.246709Z

Here the first formula is (:male user#)

awb99 2025-01-13T06:19:37.606839Z

This concept would allow to have ui symtax very clear; in fact it would look like static code.

awb99 2025-01-13T06:23:38.374329Z

I played around with walk to see how far I can come .. and it works for simple cases .. for more complex expressions it needs to build a dependency tree of expressions

awb99 2025-01-13T06:24:36.624439Z

And the only other fixed rule is that all dom elements always expect input a formula and the output is a formula as well.

awb99 2025-01-13T06:25:44.714999Z

Now it is a math problem.

awb99 2025-01-13T06:31:51.145939Z

To be fair: for matrix I guess this approach might not make sense, because matrix evaluates formulas eagerly. But for libraries that evaluation lazily (such as missionary) this concept would allow syntax to be very short.

awb99 2025-01-13T06:33:16.016069Z

Electric is doing something similar; but electric also incorporates client + server layer; andnthey use clojure analyzer; what I propose is much simpler and perhaps can work without he analyzer.

kennytilton 2025-01-13T06:34:57.101169Z

I am responding in a thread off your original Q. But now I am crashing. 🛏️

awb99 2025-01-13T06:37:40.650269Z

Good night!

awb99 2025-01-13T06:42:19.573799Z

I pasted some working snippets .. how the same code could be used for rendering static or dynamic pages on the server or even exporting a snapshot to hiccup.

kennytilton 2025-01-13T11:44:29.254909Z

I when I come back I will check the thread for your answer to my question. 🙂 The thread is here. https://clojurians.slack.com/archives/CKCBP3QF9/p1736749022506979?thread_ts=1736748293.856099&cid=CKCBP3QF9 Not that this channel has too much traffic! 🤣 But still.