Re: State & GUIs
On Dec 2, 2017 6:53 AM, "Owen"wrote: Hey all. I'm looking for hints on how to put GUIs together in Clojure. Any thoughts appreciated. The two themes that stick out for me in Clojure are considered attention to the default data structures and the radical approach to minimising state. But it seems to me that GUIs are inherently stateful and I don't have a huge amount of faith that issues around data structures have been completely thought through. Which data structures? Clojure's data structures are very well "thought through". App state != gui state. It particularly sticks out to me that Clojure itself hasn't taken a position on the subject and that the 'official' Clojure GUI language might actually be Swing or JavaFX. There is no "gui language". There are gui apis. This would be in spite of the fact that those two both bring extremely stateful objects into the Clojure world that just don't sit very neatly with the apparent vision of the language. So with this as my starting point; I don't think there is an official, idiomatic way to create a GUI. Can anyone point me in the direction of any authoritative recommendations (particularly academic literature) on how to balance GUI state and functional programming? The beginning of wisdom here is simple: traditional models of computation (Turing Machines, Lambda Definability, etc.) just do not work for interaction. Functional programming is totally orthogonal to interactionist programming. For academic lit, see Robin Milner, esp. his book on the Pi Calculus. I can tell if I have a GUI or not, but I'm looking for yardsticks to assess: 1) Is my toolkit introducing unnecessary state? 2) Am I introducing unnecessary state? 3) Are my models of inter-widget communication appropriate? Impossible to know without seeing your code. g -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: State & GUIs
Hello, Owen. Right now I'm working on the abstract UI reconciliation library: https://github.com/jetbrains/noria-clj This is created to address the issue between UI and functional programming languages. Basically it is very similar to React, except: 1) The communication between host platform (DOM, Cocoa, javax.swing, Win32 etc.) and your UI logic is done with data, not bindings. reconcile is a pure function: (reconcile [old-ui element]) => [new-ui updates] where updates is a vector of commands to be performed by the host patform and could be put on the wire. There actually a very simple set of 5 kinds of commands: - make-node ;; which creates a node on host with given ID - set-attr ;; sets some attribute of node with given ID to be a specific value - add ;; adds value to a collection of values stored as attribute of some node (say dom/children attr or NSView/subviews) - remove ;; symmetrical to add - destroy ;; destroy this node, I don't need it 2) The implementer of this commands runs on a host runtime with some traditional UI toolkit. The logic of the UI itself is written in clojure and works with plain immutable data structures and pure functions. 3) Noria differs from React in a way we treat a state of the components: the component itself is a transducer: (def my-stateful-component [r-f] (fn ([] (r-f)) ([state input] (r-f updated-state )) ([state] (r-f state))) 4) Noria allows you to create a graph of objects rather than a tree: (def constraint (render (fn [text1 text2] ['apply (fn [view1 view2] ['do {:noria/type :fake/constraint :constraint/view1 view1 :constraint/view2 view2} {:noria/type :Container :fake/children [view1 view2]}]) {:noria/type :fake/label :label/text text1} {:noria/type :fake/label2 :label2/text text2}]))) Here we have two special 'elements'. One is 'apply which gives you a reference to existing component so you could use it in different contexts. Another is 'do which behaves much like clojure's do: all components inside of it will be created, but the last one will be returned to the caller. Host side is to be open-sourced soon. DOM/js and Cocoa/objc hosts are in progress at the moment. One could implement something else. On Saturday, December 2, 2017 at 3:53:10 PM UTC+3, Owen wrote: > > Hey all. I'm looking for hints on how to put GUIs together in Clojure. Any > thoughts appreciated. > > The two themes that stick out for me in Clojure are considered attention > to the default data structures and the radical approach to minimising > state. But it seems to me that GUIs are inherently stateful and I don't > have a huge amount of faith that issues around data structures have been > completely thought through. It particularly sticks out to me that Clojure > itself hasn't taken a position on the subject and that the 'official' > Clojure GUI language might actually be Swing or JavaFX. This would be in > spite of the fact that those two both bring extremely stateful objects into > the Clojure world that just don't sit very neatly with the apparent vision > of the language. > > So with this as my starting point; I don't think there is an official, > idiomatic way to create a GUI. Can anyone point me in the direction of any > authoritative recommendations (particularly academic literature) on how to > balance GUI state and functional programming? I can tell if I have a GUI or > not, but I'm looking for yardsticks to assess: > 1) Is my toolkit introducing unnecessary state? > 2) Am I introducing unnecessary state? > 3) Are my models of inter-widget communication appropriate? > > I know that MVC/MVMC/MVA/etc exist, but I don't know how to assess their > merits against how Clojure wants me to work. > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: State & GUIs
I think the major leap functional languages (esp. CLJS because that's where it started) have made in the UI world is in the area of React-style virtual DOM setups. The overall view is this: datamodel -> view generation -> dom differ -> UI -> events -> datamodel The idea being that you can code in a very declarative way, and allow the framework to diff the UI with what the previous view of the UI was. So although this model is not strictly functional (events do have side effects) it is a declarative dataflow, and for me that's revolutionized how I do UI work. This model with originally prototyped with React, but then Om in ClojureScript introduced immutable data that can drastically cut down on the complexity of the React diffing model. All that's happened in about the last 4 years. And since then we've seen a lot of ideas from ClojureScript move into the JS world and back into React itself. From there, libraries such as my fn-fx lib (mentioned previously) are simply a React-esque virtual dom over JavaFX. Sadly though, these non JS libraries don't get a lot of exposure mostly because the vast majority of UI apps are in the browser. It's been almost 10 years since a client has asked me for a non-browser app. Timothy On Sat, Dec 2, 2017 at 6:41 PM, Raoul Dukewrote: > random tangential food for thought: > https://groups.google.com/forum/#!searchin/elm-discuss/ > Discussion$20on$20saying$20farewell$20to$20FRP$20|sort: > relevance/elm-discuss/6U74_aNXC04/UY8dIIh-CQAJ > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: State & GUIs
random tangential food for thought: https://groups.google.com/forum/#!searchin/elm-discuss/Discussion$20on$20saying$20farewell$20to$20FRP$20|sort:relevance/elm-discuss/6U74_aNXC04/UY8dIIh-CQAJ -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: State & GUIs
Owenwrites: Can anyone point me in the direction of any authoritative recommendations (particularly academic literature) on how to balance GUI state and functional programming? More generally, in addition to the specific libraries already mentioned, perhaps you might like to read up on Functional Reactive Programming (FRP)? https://en.wikipedia.org/wiki/Functional_reactive_programming Alexis. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: State & GUIs
Also take a look at re-frame (cljs) redux (js) libraries. On Sat, 2 Dec 2017 at 10:18, Moe Aboulkheirwrote: > It may make sense to familiarise yourself with the architecture of a > Clojurescript + React web application, if that's not something you've > recently investigated. Regardless of whether the techniques are directly > applicable to your problem, I think the relationship between the state and > the UI is something to aspire to. > > It may also be worth looking at https://github.com/halgari/fn-fx which is > trying to do something similar with JavaFX. > > Take care, > Moe > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- - sent from my mobile -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: State & GUIs
It may make sense to familiarise yourself with the architecture of a Clojurescript + React web application, if that's not something you've recently investigated. Regardless of whether the techniques are directly applicable to your problem, I think the relationship between the state and the UI is something to aspire to. It may also be worth looking at https://github.com/halgari/fn-fx which is trying to do something similar with JavaFX. Take care, Moe -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.