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)))
ok. and? 🙂
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!
Are you watching the Blue Origin launch? https://www.blueorigin.com/missions/ng-1
Just for context, what problem are we solving?
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)])
A normal ui function would be:
(defn user-greeting [user-id] ; non ui part (let [user (get-user user-id)] ; ui part (div (p (str "Hello " user))))
Now if we by convencion define that all input of a dom element is dynamic (a cell / formula)
And the convention is that all symbols ending with # are formulas.
This means such ui functions need to be a macro too.
Then it should be possible to infer the type of all variables, and wrap necessary conversion automatically.
Example
(def-ui [user#] (div (p (str "Hello " user#))))
In this example it is clear that (str "Hello " user#) is a formula depending on a formula; and needs to ve wrapped.
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.
I could go more complex:
(def-ui [user#] (if (:male user#) (p (str "Hello mr. " (:name user#))) (p (str "Hello mrs." (:name user#)))))
Here the first formula is (:male user#)
This concept would allow to have ui symtax very clear; in fact it would look like static code.
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
And the only other fixed rule is that all dom elements always expect input a formula and the output is a formula as well.
Now it is a math problem.
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.
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.
I am responding in a thread off your original Q. But now I am crashing. 🛏️
https://github.com/clojure-quant/missionary-test/blob/main/src/dali/mount.clj
https://github.com/clojure-quant/missionary-test/blob/main/src/dali/dom.clj
https://github.com/clojure-quant/missionary-test/blob/main/src/dali/demo/simpel.clj
https://github.com/clojure-quant/missionary-test/blob/main/src/dali/demo/clock.clj
Good night!
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.
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.