git.alexw.nyc home about git garden
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <link rel="stylesheet" type="text/css" href="../style.css">
    <link rel="icon" type="image/png" href="../icon.png">
    <title>alexw.nyc: modal in N minutes</title>
  </head>
<body>
  <header>
    <table><tr><td><a href="../index.html"><img src="../icon.png" width=20 /></a></td>
			<td>alexw.nyc</td>
			<td><a href="../index.html">home</a></td>
			<td><a href="../about.html">about</a></td>
			<td><a href="//git.alexw.nyc">git</a></td>
			<td><a href="../garden.html">garden</a></td>
		</tr></table>
  </header>
<main>
	<h1>Modal in N Minutes</h1>
<pre style="white-space: pre-wrap;">
Modal is a programming language that operates on trees, represented as strings.

(ref: x) -> comment specific to the <a href="https://git.sr.ht/~rabbits/modal">reference implementation</a>

The leaf in a tree is a symbol.
A symbol is a string, with some limitations.
A symbol cannot be equal to '<>'.
A symbol cannot contain the characters ')', ' ', and '('.
These are are all special non-symbol elements, to be described.
Here are some symbols:
  foo
  12345
  .'.'.'
The character set allowed in symbols is undefined. (ref: ASCII minus control characters)

Children in the tree are defined by sequences.
A sequence is a collection of trees, separated by spaces. 
Trees' children may also be referred to as 'elements', which are also trees (sub-trees)
A sequence is itself a tree.
Here are some trees:
  a -> a tree consisting of a symbol
  (a b) -> a tree consisting of a sequence of two symbols
  (a (b)) -> a tree consistent of a sequence of 'a' and the tree '(b)' (a sequence with one element, a symbol)

Definitions are string replacement rules created by <>.
<> is a special string that cannot be a symbol
  (ie, cannot be the leaf of a tree)
A definition is a string replacement operation.
A definition takes two "tokens", which are replacement operations that act upon trees.
  (Traversal order is undefined (ref: breadth-first))
A definition can have up to two replacement operations.
If a definition only has one operation, the right side is "".
A definition says:
  "Take a tree, that, when represented as a string, matches to 
   the rule [left], and replace it with [right]"
<> (a) (b) says: define a rule that replaces (a) with (b).
Replacements may contain registers, which are preceded by ? 
  (ref: and are a single lowercase letter)
e.g. ?a is a register
A register says:
  "find the element in this position in the input tree, store it in 
   this register, then place the element in the output tree in its 
   associated position"
Some definitions:
<> a b
<> foo
<> (swap ?x ?y) (?y ?x)
<> (if (#t) ?b) (?b)

There are three special registers, ?:, ?~, ?* and the lambda register.
?: is the output register
Instead of replacing an element, when the definition is
  applied, it will consume the element and print it to the
  console.
?~ is the input register
instead of replacing an element, when the definition is applied, it 
  will read an element (ref: whitespace-separated)_ from the console.
?* TODO

?(BODY) is the lambda register, where BODY are the two 
  tokens in a definition.
Rules created that way exist only for the length of one rewrite 
  and must match what is found immediately after.

Execution of a modal program consists of:
  1. Parsing all definitions in order, leaving only a 
     tree and its elements.
  2. Subsequently applying rules to this tree until no 
     more rules apply.
</pre>

For more information, see <a href="https://wiki.xxiivv.com/site/modal">Modal</a>.
</main>
<footer>
<a href="/tech/infra.html">live</a> from beautiful brooklyn, new york
<a href="mailto:alex@alexwennerberg.com">email</a>
<a href="https://merveilles.town/@aw">mastodon</a>
</footer>
</body>
</html>