<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: rekreanto</title>
    <description>The latest articles on DEV Community by rekreanto (@rekreanto).</description>
    <link>https://dev.to/rekreanto</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F476484%2Ffb918c45-0c0c-4676-aa43-cd9d3f804884.jpeg</url>
      <title>DEV Community: rekreanto</title>
      <link>https://dev.to/rekreanto</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rekreanto"/>
    <language>en</language>
    <item>
      <title>Unified State Expressions - Transitions (First Sketch) </title>
      <dc:creator>rekreanto</dc:creator>
      <pubDate>Fri, 13 Nov 2020 13:32:50 +0000</pubDate>
      <link>https://dev.to/rekreanto/sbn-a-textual-notation-for-state-machine-behavior-first-sketch-46kk</link>
      <guid>https://dev.to/rekreanto/sbn-a-textual-notation-for-state-machine-behavior-first-sketch-46kk</guid>
      <description>&lt;h2&gt;
  
  
  Some examples:
&lt;/h2&gt;

&lt;p&gt;The traffic light. Now with behavior&lt;/p&gt;

&lt;h3&gt;
  
  
  Non-hierarchical Traffic Light
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;
&lt;span class="c1"&gt;// State Machine Type&lt;/span&gt;
&lt;span class="nx"&gt;TrafficLight&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Green&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Yellow&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Red&lt;/span&gt;


&lt;span class="c1"&gt;// State Machine Reactions &lt;/span&gt;
&lt;span class="c1"&gt;// Collapsed view&lt;/span&gt;
&lt;span class="nx"&gt;TrafficLight&lt;/span&gt;                   &lt;span class="c1"&gt;// scope&lt;/span&gt;
  &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;NEXT&lt;/span&gt;                         &lt;span class="c1"&gt;// transition name&lt;/span&gt;

&lt;span class="c1"&gt;// State Machine Reactions&lt;/span&gt;
&lt;span class="c1"&gt;// expanded view&lt;/span&gt;
&lt;span class="nx"&gt;TrafficLight&lt;/span&gt;                   &lt;span class="c1"&gt;// scope&lt;/span&gt;
  &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;NEXT&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Green&lt;/span&gt;  &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Yellow&lt;/span&gt;      &lt;span class="c1"&gt;// reaction&lt;/span&gt;
  &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;NEXT&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Yellow&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Red&lt;/span&gt;         &lt;span class="c1"&gt;// reaction&lt;/span&gt;
  &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;NEXT&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Red&lt;/span&gt;    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Green&lt;/span&gt;       &lt;span class="c1"&gt;// reaction&lt;/span&gt;


&lt;span class="c1"&gt;// State Machine Boundary Actions&lt;/span&gt;

&lt;span class="nx"&gt;TrafficLight&lt;/span&gt;
  &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; 
  &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Green&lt;/span&gt;  &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;after&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;duration&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt; &lt;span class="nx"&gt;NEXT&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// boundary action&lt;/span&gt;
  &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Yellow&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;after&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;duration&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt; &lt;span class="nx"&gt;NEXT&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// boundary action&lt;/span&gt;
  &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Red&lt;/span&gt;    &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;after&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;duration&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt; &lt;span class="nx"&gt;NEXT&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// boundary action&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Counter
&lt;/h3&gt;

&lt;p&gt;And the almost simplest counter from 15js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;
&lt;span class="c1"&gt;// State Machine Type&lt;/span&gt;
&lt;span class="nx"&gt;Counter&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;


&lt;span class="c1"&gt;// State Machine Reactions&lt;/span&gt;
&lt;span class="c1"&gt;// collpased view&lt;/span&gt;
&lt;span class="nx"&gt;Counter&lt;/span&gt;                     &lt;span class="c1"&gt;// scope&lt;/span&gt;
  &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;INCR&lt;/span&gt;                      &lt;span class="c1"&gt;// transition name&lt;/span&gt;
  &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;RESET&lt;/span&gt;                     &lt;span class="c1"&gt;// transition name&lt;/span&gt;
  &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;DECR&lt;/span&gt;                      &lt;span class="c1"&gt;// transition name&lt;/span&gt;

&lt;span class="c1"&gt;// State Machine Reactions&lt;/span&gt;
&lt;span class="c1"&gt;// expanded view&lt;/span&gt;
&lt;span class="nx"&gt;Counter&lt;/span&gt;                     &lt;span class="c1"&gt;// scope&lt;/span&gt;
  &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;INCR&lt;/span&gt;  &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;  &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;  &lt;span class="c1"&gt;// reaction&lt;/span&gt;
  &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;RESET&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;_n&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;      &lt;span class="c1"&gt;// reaction&lt;/span&gt;
  &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;DECR&lt;/span&gt;  &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;  &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;  &lt;span class="c1"&gt;// reaction&lt;/span&gt;

&lt;span class="c1"&gt;// Note that the reconstructor part is empty&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Linksy Kitchen Timer
&lt;/h3&gt;

&lt;p&gt;(It is the timer in the banner art above.)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;
&lt;span class="c1"&gt;// State Machine Type&lt;/span&gt;
&lt;span class="nx"&gt;LinksyKitchenTimer&lt;/span&gt; 
  &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Setting&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;int&lt;/span&gt; &lt;span class="nx"&gt;min&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;int&lt;/span&gt; &lt;span class="nx"&gt;sec&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Ticking&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;int&lt;/span&gt; &lt;span class="nx"&gt;sec&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Paused&lt;/span&gt;  &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;int&lt;/span&gt; &lt;span class="nx"&gt;sec&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Alarming&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// State Machine Reactions&lt;/span&gt;

&lt;span class="nx"&gt;LinksyKitchenTimer&lt;/span&gt; &lt;span class="c1"&gt;// scope&lt;/span&gt;
    &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;START&lt;/span&gt;   &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Setting&lt;/span&gt;  &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Ticking&lt;/span&gt;  &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;  &lt;span class="c1"&gt;// reaction&lt;/span&gt;
    &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;PAUSE&lt;/span&gt;   &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Ticking&lt;/span&gt;  &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Paused&lt;/span&gt;   &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;      
    &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;CANCEL&lt;/span&gt;  &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Paused&lt;/span&gt;   &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Setting&lt;/span&gt;  &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;history&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;// residual state is memoized&lt;/span&gt;
    &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;RESTART&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Paused&lt;/span&gt;   &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Ticking&lt;/span&gt;  &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;
    &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;OK&lt;/span&gt;      &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Alarming&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Setting&lt;/span&gt;  &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;history&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;// residual state is memoized&lt;/span&gt;
    &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;TIC&lt;/span&gt;     &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Ticking&lt;/span&gt;  &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Alarming&lt;/span&gt;

&lt;span class="nx"&gt;LinksyKitchenTimer&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Ticking&lt;/span&gt;  &lt;span class="c1"&gt;// scope&lt;/span&gt;
  &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;TIC&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;gt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;  &lt;span class="c1"&gt;// reaction&lt;/span&gt;

&lt;span class="nx"&gt;LinksyKitchenTimer&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Setting&lt;/span&gt;  &lt;span class="c1"&gt;// scope&lt;/span&gt;
    &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;M10&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// reaction&lt;/span&gt;
    &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;M5&lt;/span&gt;  &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;M3&lt;/span&gt;  &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;M1&lt;/span&gt;  &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;S10&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// State Machine Boundary Actions&lt;/span&gt;
&lt;span class="nx"&gt;LinksyKitchenTimer&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Ticking&lt;/span&gt;  &lt;span class="c1"&gt;// scope&lt;/span&gt;
  &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;after&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="p"&gt;)(&lt;/span&gt; &lt;span class="nx"&gt;TIC&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;          &lt;span class="c1"&gt;// boundary action&lt;/span&gt;

&lt;span class="nx"&gt;LinksyKitchenTimer&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Alarming&lt;/span&gt;  &lt;span class="c1"&gt;// scope&lt;/span&gt;
  &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;  &lt;span class="nx"&gt;after&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="p"&gt;)(&lt;/span&gt; &lt;span class="nx"&gt;OK&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;          &lt;span class="c1"&gt;// boundary action&lt;/span&gt;
  &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;stop&lt;/span&gt; &lt;span class="nx"&gt;sound&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;           &lt;span class="c1"&gt;// boundary action&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Separate definitions are preferred
&lt;/h2&gt;

&lt;p&gt;The Behavior part seems to be 3-10 times larger than the State Type definitions if measured in SLOC. That, I think is a good argument for giving the type information separately; it might otherwise be less readable and less useful.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Unified State Expressions -  State (First Sketch)</title>
      <dc:creator>rekreanto</dc:creator>
      <pubDate>Wed, 11 Nov 2020 10:26:40 +0000</pubDate>
      <link>https://dev.to/rekreanto/towards-a-state-type-notation-for-total-state-8ej</link>
      <guid>https://dev.to/rekreanto/towards-a-state-type-notation-for-total-state-8ej</guid>
      <description>&lt;h2&gt;
  
  
  Constructs
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="s2"&gt;`alt`&lt;/span&gt;              &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;`Red`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`Green`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`Yellow`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`Guest`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`LoggedIn`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`About`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`Welcome`&lt;/span&gt;
  &lt;span class="s2"&gt;`branch`&lt;/span&gt;           &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;`@user`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`@page`&lt;/span&gt;
  &lt;span class="s2"&gt;`or`&lt;/span&gt;               &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`|`&lt;/span&gt;   &lt;span class="nx"&gt;or&lt;/span&gt; &lt;span class="s2"&gt;`---`&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;`Red`&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s2"&gt;`Green`&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s2"&gt;`Yellow`&lt;/span&gt;
  &lt;span class="s2"&gt;`branch-expand`&lt;/span&gt;    &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`:`&lt;/span&gt;   &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;`@user: Guest`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`@page: About`&lt;/span&gt;&lt;span class="err"&gt;&lt;/span&gt;
  &lt;span class="s2"&gt;`sub-expand`&lt;/span&gt;       &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`:&amp;gt;`&lt;/span&gt;  &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;`Red`&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`Walking`&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s2"&gt;`Waiting`&lt;/span&gt;
  &lt;span class="s2"&gt;`optional-sub`&lt;/span&gt;     &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`:&amp;gt;`&lt;/span&gt;  &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nx"&gt;EditEvents&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt;
                                             &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;SelectedEvent&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                                             &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;CreatedEvent&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="s2"&gt;`atomic-marker`&lt;/span&gt;    &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`.`&lt;/span&gt;   &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;`Green.`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`Yellow`&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="c1"&gt;// optional&lt;/span&gt;
  &lt;span class="s2"&gt;`composite-marker`&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`...`&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;`Red...`&lt;/span&gt; &lt;span class="c1"&gt;// optional&lt;/span&gt;
  &lt;span class="s2"&gt;`agnostic-view`&lt;/span&gt;    &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="c1"&gt;// the omission of atomic/composite marker&lt;/span&gt;
  &lt;span class="s2"&gt;`system-types`&lt;/span&gt;     &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`&amp;lt;...&amp;gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="nx"&gt;such&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-- Alternatives (or-states) or Branches (and-states) is per default shown collapsed. The next step, the refinement/branch value, can be shown using the expand-constructs &lt;code&gt;:&amp;gt;&lt;/code&gt; or &lt;code&gt;:&lt;/code&gt;. Atomic states, marked per a trailing dot &lt;code&gt;.&lt;/code&gt; cannot be expanded.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sample STN Notation for some Traditional Toy State Machine Examples
&lt;/h2&gt;

&lt;h3&gt;
  
  
  TrafficLight from xstate.js.org
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://xstate.js.org/docs/guides/hierarchical.html"&gt;Example source&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
  &lt;span class="c1"&gt;// agnostiv view (we don't express whether or not there are refined states)&lt;/span&gt;
  &lt;span class="nx"&gt;TrafficLight&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Green&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Yellow&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Red&lt;/span&gt;


  &lt;span class="c1"&gt;// Collapsed explicit view (denotes atomic/compsed nature of states)&lt;/span&gt;
  &lt;span class="nx"&gt;TrafficLight&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; 
               &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Green&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
               &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Yellow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
               &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Red&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="c1"&gt;// can be expanded&lt;/span&gt;


  &lt;span class="nx"&gt;TrafficLight&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; 
               &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Green&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; 
               &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Yellow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
               &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Red&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;// expanded view of Red&lt;/span&gt;
                     &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Walking&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
                     &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Waiting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
                     &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Stopped&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
                     &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Blinking&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Counter toy app from 7GUIs
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://eugenkiss.github.io/7guis/tasks#counter"&gt;Example source&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;
&lt;span class="nx"&gt;Counter&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  TempConv toy app from 7GUIs
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://eugenkiss.github.io/7guis/tasks#temp"&gt;Example source&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// agnostic view&lt;/span&gt;
&lt;span class="nx"&gt;TempConv&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;F2C&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;C2F&lt;/span&gt;

&lt;span class="c1"&gt;// expanded view&lt;/span&gt;

&lt;span class="nx"&gt;TempConv&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; 
         &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;F2C&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="nx"&gt;Fahrenheit&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
         &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;C2F&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="nx"&gt;Celcius&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="c1"&gt;// this is all the essential state needed to restore the app to its state&lt;/span&gt;
&lt;span class="c1"&gt;// the source number as well as the converted number are derived from the input string&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Sample small website GrowersAssociationSite (GA_Site)
&lt;/h3&gt;

&lt;p&gt;Source: This is part of a (toy) site I'm working on as part of my web design educaton.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;
&lt;span class="c1"&gt;// collapsed view&lt;/span&gt;
&lt;span class="nx"&gt;GA_Site&lt;/span&gt; 
  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;lang&lt;/span&gt;
  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;user&lt;/span&gt;
  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;page&lt;/span&gt;



&lt;span class="c1"&gt;// expanded view&lt;/span&gt;
&lt;span class="nx"&gt;GA_Site&lt;/span&gt; 
  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;lang&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;sv&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;en&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;ja&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;eo&lt;/span&gt;
  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;user&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Guest&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;LoggedIn&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="nx"&gt;UserName&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;page&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;About&lt;/span&gt; 
        &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Join&lt;/span&gt; 
        &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Calendar&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; 
                   &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;BrowseEvents&lt;/span&gt;
                   &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;EditEvents&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt;
                                &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;SelectedEvent&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                                &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;CreatedEvent&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                                &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;UpdatedEvent&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; 
                                &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;DeletedEvent&lt;/span&gt;  &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="nx"&gt;descr&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;
                                &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;UndidDeletion&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;




&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>This is a brilliant explanation of Orthogonal States by David Harel... using babies</title>
      <dc:creator>rekreanto</dc:creator>
      <pubDate>Wed, 07 Oct 2020 06:51:52 +0000</pubDate>
      <link>https://dev.to/rekreanto/this-is-a-great-explanation-of-orthogonal-states-by-david-harel-using-babies-40h5</link>
      <guid>https://dev.to/rekreanto/this-is-a-great-explanation-of-orthogonal-states-by-david-harel-using-babies-40h5</guid>
      <description>&lt;p&gt;Look at he banner art above. It is the classic Statechart visual language that we all know and love: useful for modeling behavior for example in a reactive app. &lt;em&gt;But now imagine the same visual formalism populated with cute babies&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uPG_JznW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o8pc4yamo3yljmbym8aw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uPG_JznW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o8pc4yamo3yljmbym8aw.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is David Harel, author of the original Statechart paper from 1987, explaining &lt;code&gt;Orthogonal states&lt;/code&gt; using babies. It is mind-blowingly endearing and accessible. (Full transcript scrolling in the sidebar etc.) The video appears as part of the excellent edX course &lt;a href="https://www.edx.org/course/programming-for-everyone-an-introduction-to-visual"&gt;"Programming for Everyone – An Introduction to Visual Programming Languages" (formerly Liberate Programming)&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Anyone with the slightest interest in Statecharts, or programming, or... just loves poignant anecdotes will love this course. It is entry level, I think no one will feel excluded. Advanced learners might enjoy it for the sheer joy and clarity it radiates. Also, it is never too early to get the mental models of the fundamental concepts right :-) Or you could just wait for &lt;a href="https://mastery.games/"&gt;David Geddes&lt;/a&gt; to publish a Statechart mastery game :-).&lt;/p&gt;

</description>
      <category>ui</category>
      <category>cs</category>
      <category>statecharts</category>
      <category>davidharel</category>
    </item>
    <item>
      <title>[ Art of The State ] What is a HTML tag if the browser is a state machine?</title>
      <dc:creator>rekreanto</dc:creator>
      <pubDate>Thu, 01 Oct 2020 12:10:54 +0000</pubDate>
      <link>https://dev.to/rekreanto/the-art-of-the-state-part-i-what-is-a-html-tag-if-the-browser-is-a-state-machine-47cp</link>
      <guid>https://dev.to/rekreanto/the-art-of-the-state-part-i-what-is-a-html-tag-if-the-browser-is-a-state-machine-47cp</guid>
      <description>&lt;p&gt;A note to any presumptive reader: &lt;em&gt;This is an ongoing sketch done during a quest to understand what state machines can do for UI construction. Code samples are only intended as art, i.e. hopefully illustrative, possibly interesting, only accidentally executable.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A web page is a &lt;em&gt;state&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;Once upon a time, all web pages were static. Then the situation was simple: The browser was in the same &lt;strong&gt;state&lt;/strong&gt; as long as the same web page was shown. &lt;/p&gt;

&lt;h2&gt;
  
  
  Clicking  link triggers a &lt;em&gt;transition&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;When the user clicked a link, the browser performed a &lt;strong&gt;transition&lt;/strong&gt; to another state. These states can be represented by the URL. But what we as users see on the screen is the result of the browser loading and rendering a html page that corresponds to the URL. What we observe is a very simple state machine. We now understands the browser and the web page using sate machine concepts.&lt;/p&gt;

&lt;h2&gt;
  
  
  So what is a HTML tag?
&lt;/h2&gt;

&lt;p&gt;Lets now zoom in our view and consider a single HTML tag. What is it and where do it belong? We can observe it: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When the html file is loaded and the document is parsed, a given HTML tag will be realized as a DOM element and typically rendered to the screen. &lt;/li&gt;
&lt;li&gt;When the user has clicked a non-local link and the current page unloads, the DOM element is deleted.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  A HTML tag represents a &lt;em&gt;boundary action&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;So because the exists in the html file, a node is created upon ENTRY of the web page as a state, and then deleted when the state EXITS. This means that a HTML tag stands for a combination of and Entry action and an Exit action. For convenience, lets call that a &lt;strong&gt;boundary action&lt;/strong&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Boundary actions are natural and helpful
&lt;/h2&gt;

&lt;p&gt;While the term "Boundary Action" is not typically part of State machine terminology, it has two advantages: It is convenient and it can offer something any sane entry action would kill for: The opportunity to undo what the entry action has done. For example, a friendly implementation will keep the environment in which the entry action was executed alive until the corresponding exit action executes. Let's say the an entry action starts a timer that will trigger a transition after 10 seconds. Then a user events causes the state to transition after only 3 seconds. Since the timer is implemented as a boundary action, it can delete the timer as part of it's exit action.&lt;/p&gt;

&lt;h2&gt;
  
  
  So let's implement a HTML tag as a boundary action
&lt;/h2&gt;

&lt;p&gt;Assuming we have a state machine that controls the internals of a web page, and that each state accepts boundary actions, how can we implement a HTML tag? Let's give it a try:&lt;/p&gt;

&lt;p&gt;Upon entry of the state, the tag should &lt;em&gt;create a DOM element&lt;/em&gt;. Upon exit, the element should &lt;em&gt;be removed&lt;/em&gt;. In order to keep hold on the environment that the boundary action needs, we use double closures in the spirit of Reified Continuation Passing Style, see &lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/rekreanto" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F476484%2Ffb918c45-0c0c-4676-aa43-cd9d3f804884.jpeg" alt="rekreanto"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/rekreanto/why-it-is-impossible-to-write-an-identity-function-in-javascript-and-how-to-do-it-anyway-2j51" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;[ The Art of the State ] Why it is impossible to write an Identity Function in JavaScript, and how to do it anyway&lt;/h2&gt;
      &lt;h3&gt;rekreanto ・ Sep 28 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#ephemerals&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#continuations&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;First iteration:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; 
  &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;tagname&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;     &lt;span class="c1"&gt;// defined by user&lt;/span&gt;
&lt;span class="c1"&gt;// ::::: [ definition time above ] ::::: [ mount time below ] :::::&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;parent&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;     &lt;span class="c1"&gt;// given by the implementation&lt;/span&gt;
&lt;span class="c1"&gt;// ::::: [ mount time above      ] ::::: [ runtime below    ] :::::&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt;        &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;   &lt;span class="c1"&gt;// called upon entry&lt;/span&gt;
  &lt;span class="c1"&gt;// ENTRY ACTIONS&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;tagname&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;    &lt;span class="c1"&gt;// called upon exit&lt;/span&gt;
    &lt;span class="c1"&gt;//EXIT ACTIONS&lt;/span&gt;
    &lt;span class="nx"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Oh, it seems we have forgotten something? Non-atomic HTML tags can have content, i.e. other HTML tags. It is a really bad idea to forget about one's kids!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second iteration:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; 
  &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;tagname&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;              &lt;span class="c1"&gt;// defined by user&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;boundaryActions&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;   &lt;span class="c1"&gt;// also defined by user&lt;/span&gt;
&lt;span class="c1"&gt;// ::::: [ definition time above ] ::::: [ mount time below ] :::::&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;parent&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;              &lt;span class="c1"&gt;// given by the implementation&lt;/span&gt;
&lt;span class="c1"&gt;// ::::: [ mount time above      ] ::::: [ runtime below    ] :::::&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt;        &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;            &lt;span class="c1"&gt;// called upon entry&lt;/span&gt;
  &lt;span class="c1"&gt;// ENTRY ACTIONS&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;tagname&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;entryActions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;boundaryActions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;bAct&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;bAct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;parent&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;exitActions&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;entryActions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;enAct&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;enAct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;              &lt;span class="c1"&gt;// called upon exit&lt;/span&gt;
    &lt;span class="c1"&gt;//EXIT ACTIONS&lt;/span&gt;
    &lt;span class="nx"&gt;exitActions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;exAct&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;exAct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// cleanup children&lt;/span&gt;
    &lt;span class="nx"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// cleanup self&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Sample HTML &lt;/span&gt;
&lt;span class="c1"&gt;// N.B. strings and objects are not supported &lt;/span&gt;
&lt;span class="c1"&gt;// as boundary actions in the code above&lt;/span&gt;
&lt;span class="nf"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;div&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;h1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;The Art of The State, part I&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;)(&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;...hopefully illustrative, possibly interesting, certainly useless&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;h2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Are we there yet?&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Short answer: No.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;placeholder&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;WHY NOT?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ol&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;li&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ENTRY ACTIONS&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;li&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;EXIT ACTIONS&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Are we there yet?
&lt;/h2&gt;

&lt;p&gt;Short answer: No.&lt;/p&gt;

&lt;p&gt;So, assuming we have a state machine that controls our web page, can we add HTML content in a safe and sane way?&lt;br&gt;
Well, I think we nailed the essentials: To uncreate in the exit action all that we created in the entry action.&lt;br&gt;
But, alas we cannot create any visible DOM nodes, yet. One way to do that would be to look for any string among the boundaryActions inputs, and promote it to boundary action, and make a deletable text node from it. Also, we have no way of adding attributes to the element. That could be done in a similar fashion, looking for an object to promote to boundary action, thus adding/deleting its props to our DOM node. (This way of interpreting data types as something else is used to great advantage in both jQuery and Hiccup.)&lt;/p&gt;

&lt;p&gt;Also we should add a variant of out tag implementation that, in the spirit of jQuery don't create a DOM node, but looks it up and allows modifications.&lt;/p&gt;

&lt;p&gt;Third, the notion of context is probably incomplete, since, when we map events to transitions, we have no where to send the transition. The DOM creation actions had &lt;code&gt;parent&lt;/code&gt;, maybe the event handlers need something similar.&lt;/p&gt;

&lt;h2&gt;
  
  
  How might those boundary actions be useful?
&lt;/h2&gt;

&lt;p&gt;This is utterly useless in the case described above, where every web page is static. But consider the typical case in 2020, when almost every web page has dynamic elements, then we have  different landscape: We can define a web-page according to a plan. A plan where states are explicit and all DOM creation and manipulation can occur absolutely only in one place, namely on the borders of the states. And every action that performs a mutation will also undo that mutation at the exactly appropriate point in time: &lt;em&gt;when it's state exits&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;We found out that under the assumption that the browser is a state machine, and that to visit a page is to be in a state, &lt;strong&gt;a HTML tag represents a Boundary Action&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Also, under the further assumption that aspects of a web page can change while it is visited, and that these changes are reified as states, the place where DOM is specified, can no more be restricted to the html file. But in stead of spreading out DOM manipulation to anywhere in any script, &lt;em&gt;we concluded that DOM must be described relative to the current state, and thus can only occur in the form of boundary actions attached to the states&lt;/em&gt;. &lt;/li&gt;
&lt;li&gt;We found that implementing the boundary actions using double closures, we could provide an encapsulated environment where the boundary action could hold on to references needed for clean-up work during exit.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Open questions:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;What do we need on order to make it possible to define event handlers as boundary actions? (i.e. how to support some way to make transitions able to influence the state of the machine)&lt;/li&gt;
&lt;li&gt;What primitives do we need for the state machine that is just assumed in this post?&lt;/li&gt;
&lt;li&gt;Which primitives can be boundary actions, and which need to 
be something else?&lt;/li&gt;
&lt;li&gt;So instead of a state machine, where states are combines using branching and choice, we are talking about a UI machine, where &lt;em&gt;User Interfaces combines using branching and choice&lt;/em&gt;?&lt;/li&gt;
&lt;li&gt;Then we should have a primitive that creates a User Interface, taking as parameters boundary actions and sub-UI's?&lt;/li&gt;
&lt;li&gt;How to support parameterised states? Can update functions be base case transitions, and can we have "duck stating"*&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;duck stating -- a term formed after &lt;a href="https://wiki.c2.com/?DuckTyping" rel="noopener noreferrer"&gt;"duck typing"&lt;/a&gt;, where a type is not what something &lt;em&gt;is&lt;/em&gt; but wht it can be &lt;em&gt;used as&lt;/em&gt;. Thus, under suck stating, state can be used wither as qualitative state or quantitative state or both.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Can duck stating allow update functions to be used as base case transitions?&lt;/li&gt;
&lt;li&gt;Can duck stating be a key to naturally fit in parameterized states (param-or)?&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>[ The Art of the State ] Why it is impossible to write an Identity Function in JavaScript, and how to do it anyway</title>
      <dc:creator>rekreanto</dc:creator>
      <pubDate>Mon, 28 Sep 2020 19:08:19 +0000</pubDate>
      <link>https://dev.to/rekreanto/why-it-is-impossible-to-write-an-identity-function-in-javascript-and-how-to-do-it-anyway-2j51</link>
      <guid>https://dev.to/rekreanto/why-it-is-impossible-to-write-an-identity-function-in-javascript-and-how-to-do-it-anyway-2j51</guid>
      <description>&lt;h2&gt;
  
  
  Table Of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Section I:&lt;/strong&gt; Why it is impossible...&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Section II:&lt;/strong&gt; How to do it anyway&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Section III:&lt;/strong&gt; Is there a cure for CPS Ugliness?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Summary:&lt;/strong&gt; Ephemeral values makes CPS appear natural and readable&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Section I:&lt;/strong&gt; Why it is impossible... &lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;An Identity function is a function that does nothing. It just returns what it receives. It's like the number zero, it's just there to fill the place without doing anything, and sometimes that is exactly what is needed.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So let's try to write an identity function in JavaScript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Let's try it out&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;id&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;            &lt;span class="cm"&gt;/* =&amp;gt; 42 */&lt;/span&gt;

&lt;span class="nf"&gt;id&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;forty-two&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="cm"&gt;/* =&amp;gt; "forty-two" */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Our identity function works perfectly, doesn't it?&lt;br&gt;
But what about this?&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;id&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;43&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;         &lt;span class="cm"&gt;/* =&amp;gt; 42 */&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;...Ouch!&lt;/strong&gt; &lt;em&gt;We forgot the case where there are multiple input values.&lt;/em&gt; &lt;strong&gt;Lets fix that.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;xs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;xs&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cm"&gt;/* Syntax error */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;xs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;xs&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="cm"&gt;/* Not identity any more */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Clearly this is not going well. What is the problem?&lt;/p&gt;
&lt;h2&gt;
  
  
  You can't write a real identity function in JavaScript nor in most languages
&lt;/h2&gt;

&lt;p&gt;The problem is that there is no such thing as "multiple values" outside of function invocations. Unlike natural languages, there is no plural. &lt;/p&gt;
&lt;h2&gt;
  
  
  What is plural?
&lt;/h2&gt;

&lt;p&gt;You know that you are talking about plural when a "plural" of one is the same thing as that one thing. This is for example not true for an array of one. &lt;code&gt;[42]&lt;/code&gt; is not the same as &lt;code&gt;42&lt;/code&gt;. So arrays doesn't qualify as plural. Function invocation syntax is typicly the only place where plural is expressed in a programming langauge. (In Haskell it's complicated though.)&lt;/p&gt;
&lt;h2&gt;
  
  
  You probably don't have plural and thus can't express an identity function in your favourite language too
&lt;/h2&gt;

&lt;p&gt;This is actually true for almost all programming languages. These is an asymmetry. A function can in no way return exactly what it received. Of course a function can return an array of it's arguments, but that is not the same thing. Doing that, the function then depends on the programmer to remember to splash the array when used as input to the next function call. But convention is not the same as language support. &lt;em&gt;It simply can't be done as part of the language, only as part of an ad-hoc convetion, upheld by programmer discipline&lt;/em&gt;. The only language I know of that has plural in some meaningful sense is APL/J. I think.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So to summarize:&lt;/strong&gt; You can't have a real identity function in most programming languages, because plural is not first class, and do not exist outside of function invocation syntax.&lt;/p&gt;
&lt;h1&gt;
  
  
  &lt;strong&gt;Section II:&lt;/strong&gt; How to do it anyway &lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;Now it seems quite impossible to write an identity function in JavaScript. Surely only the ECMA-committee can fix that?&lt;/p&gt;
&lt;h2&gt;
  
  
  The lack of symmetry, and how to fix it
&lt;/h2&gt;

&lt;p&gt;I don't know about you, but this blatant asymmetry of the most fundamental building block is kind of not-so-beautiful, I think. It would be quite nice to be able to fix this!&lt;/p&gt;

&lt;p&gt;So is there a way around it? Is there a way that we can program in JavaScript using perfectly symmetrical functions that has the ability, the &lt;em&gt;super-power&lt;/em&gt; of not only accepting multiple values, but also returning them?&lt;/p&gt;
&lt;h2&gt;
  
  
  CPS to the rescue
&lt;/h2&gt;

&lt;p&gt;CPS is short for &lt;em&gt;Continuation Passing Style&lt;/em&gt;. CPS is often described considered as counter-intuitive and hard to wrap your head around. The basic idea is straight-forward, though. In stead of just returning a value, every function takes as an argument its &lt;em&gt;continuation&lt;/em&gt; (the next function); and then it applies the continuation to whatever it wants to pass on. And since the applying is done by the giving function, it has a much greater freedom that a function that just returns value; one could sensibly call this is &lt;em&gt;function application with consent&lt;/em&gt;. More precisely this collaboration between function and arguments is in fact so powerful, that &lt;em&gt;any kind of control flow can be expressed&lt;/em&gt; under Continuation passing style. This is &lt;em&gt;awesome&lt;/em&gt;: Among the new superpowers that we have gained are the ability to  &lt;em&gt;return any number of values&lt;/em&gt;! Plural is resurrected! &lt;strong&gt;We have symmetric functions&lt;/strong&gt; that can express any control flow without any built-in language support. Programmers are now empowered and liberated, and resides &lt;em&gt;on the same level as the language creators&lt;/em&gt;. Empowered is an understatement! It should come as no surprise that we can actually express our identity function:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* `K` is often used to name the Continuation */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cps_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;xs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;K&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;K&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;xs&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;log&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;xs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;xs&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;cps_id&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;43&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cm"&gt;/* console: 42 43 */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;So, with some caveats, we have actually a real identity function! Two problems are: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;em&gt;All of our code must be written in CPS style&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;CPS style code is harder to read and thus adds incidental complexity&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Lets save the problem of how to lift all of JavaScript into the CPS world for another post, and focus on the readability problem.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Section III:&lt;/strong&gt; Is there a cure for CPS Ugliness? &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;CPS is actually not only incomparably more empowering and powerful than than traditional applicative code, but also at least as readable! Let's refactor the above formulation of &lt;code&gt;real_id&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* Traditional CPS style: */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;old_cps_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;xs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;K&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;K&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;xs&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="cm"&gt;/* Ephemeral CPS style: */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Tuple&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;xs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;K&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;K&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;xs&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cps_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;xs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Tuple&lt;/span&gt;&lt;span class="p"&gt;(..&lt;/span&gt;&lt;span class="nx"&gt;xs&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;OK, let's break that down!&lt;br&gt;
First we defined a helper function that encapsulates the Continuation passing. It happens to be identical to the cps version of the identity function that we were looking for all along! That's a bit confusing but it will be clearer with a couple of examples. But first note how the &lt;code&gt;cps_id&lt;/code&gt; went from mind-bending to normal, using just this helper (actually a rebranded version of itself). &lt;/p&gt;
&lt;h2&gt;
  
  
  First a real example of the usefulness of Ephemeral CPS
&lt;/h2&gt;

&lt;p&gt;Sometimes a function just naturally returns two values, e.g. &lt;code&gt;divrem&lt;/code&gt;; a function that returns the integer quotient as well as the modulo.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* Ephemeral CPS style: */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;divrem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Tuple&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="cm"&gt;/* The CPS application chain is more uniform if we start with `Tuple` */&lt;/span&gt;
&lt;span class="nc"&gt;Tuple&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;divrem&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="cm"&gt;/* console: 4 2 */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now we see how much more natural and readable the code gets if we encapsulate the continuation-passing in a function. N.B. that we need not call the Ephemeral value constructor &lt;code&gt;Tuple&lt;/code&gt;, we could just as well call it &lt;code&gt;Number&lt;/code&gt; or &lt;code&gt;String&lt;/code&gt; (if those names were not already used), if what we return is a Number or String, or we could do runtime type-checking using a typed variant of &lt;code&gt;Tuple&lt;/code&gt;etc:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;plus&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;divrem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Tuple&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;So we can see that in actual code, we can encapsulate the continuation-passing. This means that we have an intermediate value in the middle of the computation that is a closure waiting for a function that wants to be applied. For this intermediate closure, I propose the term &lt;em&gt;ephemeral value&lt;/em&gt;, because conceptually it is a value, while in practice it's just a closure waiting to concensualy accept a function in the way it self chooses to do it. CPS expressed using ephemeral values  is readable and fits naturally into the programmers mental model of the computation.&lt;/p&gt;
&lt;h1&gt;
  
  
  &lt;strong&gt;Summary:&lt;/strong&gt; Ephemeral values makes CPS appear natural and readable &lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;We saw that &lt;em&gt;a real identity function can be expressed in a restricted variant of JavaScript, called CPS&lt;/em&gt;, and that this identity function can be used to construct what we chose to call an "ephemeral value", that is something we can think of as a  value but that in practice is a closure taking as its argument the Function that wants to be applied to the value, thus encapsulating CPS.&lt;br&gt;
We saw that CPS can both easy to read and easy to grasp when we encapsulate it as ephemeral values. We can contemplate a chain of function applications as a duality between the functions and the intermediate values that has a brief existence in between function applications (or not so brief, if we want to wait for some reason).&lt;/p&gt;

&lt;p&gt;Well that's enough for now. Kinda cool how a simple identity function can encapsulate CPS like that!&lt;/p&gt;
&lt;h2&gt;
  
  
  Open questions:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Can we lift the whole of JavaScript into Ephemeral CPS? Would we want to?&lt;/li&gt;
&lt;li&gt;Can we to implement AMB as an ephemeral value? And then export it back to real js, so we can actually use it?&lt;/li&gt;
&lt;li&gt;Can we make hierarchical ephemeral values? Dispatching trunkward, applying leafward? What are the differences? Similarities?&lt;/li&gt;
&lt;li&gt;Can we parameterize ephemeral values with boundary actions thus mimicking State as in State Machines? We probably need a lot more for that to work out?&lt;/li&gt;
&lt;li&gt;Can we build a minimal embedded language for Hierarchical state machines using ephemeral values with boundary actions if we just add situated transitions?&lt;/li&gt;
&lt;li&gt;Can we add some DOM manipulation and get Hierarchical UI machines, where the fundamental component in stead of being a State is a UI?&lt;/li&gt;
&lt;li&gt;What is your favourite open question? Please Comment!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note: In a follow-up post I use the term Reified Continuation Passing Style to describe CPS encapsulated in Ephemeral values &lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/rekreanto" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F476484%2Ffb918c45-0c0c-4676-aa43-cd9d3f804884.jpeg" alt="rekreanto"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/rekreanto/the-art-of-the-state-part-i-what-is-a-html-tag-if-the-browser-is-a-state-machine-47cp" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;[ Art of The State ] What is a HTML tag if the browser is a state machine?&lt;/h2&gt;
      &lt;h3&gt;rekreanto ・ Oct 1 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



</description>
      <category>ephemerals</category>
      <category>continuations</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
