experiments/experimental-syntax.tng2
author Tony Garnock-Jones <tonygarnockjones@gmail.com>
Wed, 16 Jan 2019 17:15:58 +0000
changeset 438 1fe179d53161
parent 8 7e193a2d4679
permissions -rw-r--r--
Add missing primitive implementation for the plain interpreter.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     1
"
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     2
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     3
So, let's assume data constructors for
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     4
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     5
 - labelled product types
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     6
 - unlabelled product types
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     7
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     8
What about sum types? What about lists?
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     9
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    10
 label: value label: value label: value
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    11
 a, b, c
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    12
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    13
Core lazy lambda:
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    14
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    15
 - application
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    16
 - abstraction
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    17
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    18
Reinterpreting these in a reflective lambda:
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    19
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    20
 - split application up:
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    21
   - substitution
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    22
   - evaluation
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    23
 - abstraction stays.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    24
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    25
Syntax for lazy lambda:
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    26
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    27
 - application: adjacency?
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    28
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    29
     writeLine ""Hello, World!""
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    30
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    31
 - abstraction: some kind of block syntax
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    32
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    33
     (pattern -> expr)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    34
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    35
(define (parse-results-next results)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    36
  (let ((next (parse-results-next* results)))
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    37
    (if (procedure? next)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    38
	(let ((next-value (next)))
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    39
	  (set-parse-results-next! results next-value)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    40
	  next-value)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    41
	next)))
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    42
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    43
"
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    44
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    45
module packrat
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    46
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    47
(
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    48
  let: next be: (atomic: get: next*: results),
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    49
  if: (procedure?: next)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    50
    then: (let: next-value be: (apply: next),
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    51
           atomic: set: (next*: results) to: next-value,
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    52
           next-value)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    53
    else: next
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    54
)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    55
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    56
[
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    57
  tvar <- results next*.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    58
  [
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    59
    next <- tvar value.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    60
    next procedure?
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    61
     ifTrue: [next-value <- next apply.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    62
              tvar value: next-value.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    63
              next-value]
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    64
     ifFalse: [next]
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    65
  ] atomic
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    66
]
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    67
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    68
[
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    69
  results next* -> tvar.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    70
  [
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    71
    tvar value -> next.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    72
    next procedure?
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    73
      ifTrue: [next apply -> next-value.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    74
               tvar value: next-value.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    75
               next-value]
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    76
      ifFalse: [next]
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    77
  ] atomic
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    78
]
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    79
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    80
Collection do: Block
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    81
(-> (c, b).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    82
1 to: (c size) do: (-> i. b apply: (c at: i)).)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    83
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    84
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    85
-> results.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    86
results next* -> tvar.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    87
[
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    88
  tvar value -> next.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    89
  next procedure?
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    90
    ifTrue: [$next -> next-value.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    91
             tvar value: next-value.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    92
             next-value]
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    93
    ifFalse: [next].
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    94
] atomic.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    95
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    96
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    97
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    98
-> (list @ Pair car: a cdr: d, block @ -> _ . _).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    99
Pair car: ($block a) cdr: (d map: block).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   100
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   101
-> (Nil, block @ -> _ . _).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   102
Nil.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   103
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   104
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   105
myList map: (-> e. e + 3) -> result.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   106
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   107
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   108
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   109
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   110
-> results.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   111
next* results -> tvar.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   112
atomic [
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   113
  value tvar -> next.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   114
  if: procedure? next
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   115
    then: [$next -> next-value.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   116
           tvar value: next-value.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   117
           next-value]
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   118
    else: [next].
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   119
].
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   120
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   121
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   122
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   123
bind (-> over: (list @ Pair car: a cdr: d) map: (block @ -> _ . _).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   124
      Pair car: ($block a) cdr: (over: d map: block)).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   125
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   126
bind (-> over: Nil map: (block @ -> _ . _).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   127
      Nil).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   128
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   129
bind (-> succ (i @ Integer). i + 1).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   130
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   131
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   132
bind (-> merge: (e1 @ ParseErrors _) with: e2                   . e1).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   133
bind (-> merge: e1                   with: (e2 @ ParseErrors _) . e2).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   134
bind (-> merge: (e1 @ ParseErrors pos: p1 \ _)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   135
         with:  (e2 @ ParseErrors pos: p2 \ _).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   136
  cond: (
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   137
    [[p1 > p2] || [empty? e2]] => [e1],
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   138
    [[p2 > p1] || [empty? e1]] => [e2]
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   139
  ) else: [ParseErrors pos: p1
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   140
                       expected: (union (expected e1, expected e2))
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   141
                       messages: (append (messages e1, messages e2))]).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   142
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   143
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   144
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   145
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   146
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   147
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   148
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   149
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   150
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   151
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   152
bind (-> over: list @ Pair^(car: a cdr: d)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   153
         map: block @ (-> _ . _).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   154
      Pair^ car: ($block a) cdr: (over: d map: block)).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   155
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   156
bind (-> over: list @ Nil^_
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   157
         map: block @ (-> _ . _).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   158
      list).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   159
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   160
bind (-> succ (i @ Integer^_). i + 1).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   161
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   162
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   163
bind (-> merge: (e1 @ ParseErrors^_) with: e2                   . e1).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   164
bind (-> merge: e1                   with: (e2 @ ParseErrors^_) . e2).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   165
bind (-> merge: (e1 @ ParseErrors^ pos: p1 \ _)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   166
         with:  (e2 @ ParseErrors^ pos: p2 \ _).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   167
  cond: (
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   168
    [[p1 > p2] || [empty? e2]] => [e1],
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   169
    [[p2 > p1] || [empty? e1]] => [e2]
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   170
  ) else: [ParseErrors^ pos: p1
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   171
                        expected: expected e1 `union` expected e2
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   172
                        messages: messages e1 `append` messages e2]).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   173
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   174
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   175
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   176
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   177
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   178
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   179
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   180
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   181
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   182
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   183
bind (-> over: list @ Pair{car: a cdr: d}
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   184
         map: block @ (-> _ . _).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   185
      Pair{car: ($block a) cdr: (over: d map: block)}.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   186
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   187
bind (-> over: list @ Nil{}
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   188
         map: block @ (-> _ . _).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   189
      list).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   190
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   191
bind (-> succ (i @ Integer{}). i + 1).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   192
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   193
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   194
bind (-> merge: e1 @ ParseErrors{} with: e2                 . e1).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   195
bind (-> merge: e1                 with: e2 @ ParseErrors{} . e2).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   196
bind (-> merge: e1 @ ParseErrors{pos: p1 expected: x1 messages: m1}
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   197
         with:  e2 @ ParseErrors{pos: p2 expected: x2 messages: m2}
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   198
.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   199
  Cond {
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   200
    [[p1 > p2] || [empty? e2]] => [e1],
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   201
    [[p2 > p1] || [empty? e1]] => [e2]
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   202
  } else: [ParseErrors{pos: p1
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   203
                       expected: x1 `union` x2
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   204
                       messages: m1 `append` m2}]
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   205
).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   206
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   207
bind (-> next results @ ParseResults{next: tvar} .
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   208
  atomic [
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   209
    !tvar -> next.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   210
    if: procedure? next
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   211
      then: [$next -> next-value.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   212
             tvar := next-value.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   213
             next-value]
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   214
      else: [next].
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   215
  ].
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   216
).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   217
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   218
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   219
[
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   220
  "This is to parse as 'meta (-> m. ...)'."
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   221
  meta -> m.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   222
  dict at: key ifAbsent: [m `return` false] -> val.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   223
  val
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   224
]
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   225
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   226
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   227
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   228
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   229
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   230
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   231
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   232
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   233
"Now, experiment without the [] syntax for nullary functions"
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   234
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   235
bind (-> merge: e1 @ ParseErrors{} with: e2                 . e1).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   236
bind (-> merge: e1                 with: e2 @ ParseErrors{} . e2).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   237
bind (-> merge: e1 @ ParseErrors{pos: p1 expected: x1 messages: m1}
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   238
         with:  e2 @ ParseErrors{pos: p2 expected: x2 messages: m2}
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   239
.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   240
  Cond {
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   241
    (. (. p1 > p2) || (. empty? e2)) => (. e1),
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   242
    (. (. p2 > p1) || (. empty? e1)) => (. e2)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   243
  } else: (. ParseErrors{pos: p1
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   244
                       expected: x1 `union` x2
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   245
                       messages: m1 `append` m2})
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   246
).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   247
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   248
bind (-> next results @ ParseResults{next: tvar} .
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   249
  atomic (. 
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   250
    !tvar -> next.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   251
    if: procedure? next
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   252
      then: (. $next -> next-value.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   253
             tvar := next-value.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   254
             next-value)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   255
      else: (. next).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   256
  ).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   257
).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   258
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   259
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   260
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   261
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   262
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   263
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   264
"Now, reimagine everything as lazy - so each expression is effectively a nullary thunk."
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   265
"Note that pattern-matching is what forces promises!"
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   266
"We add syntactic sugar for lists here."
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   267
"Spineless, tagless G-machine?..."
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   268
"Monad? Is the interpreter the monad? How does polymorphic return work?"
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   269
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   270
bind (-> merge: e1 @ ParseErrors{} with: e2                 . e1).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   271
bind (-> merge: e1                 with: e2 @ ParseErrors{} . e2).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   272
bind (-> merge: e1 @ ParseErrors{pos: p1 expected: x1 messages: m1}
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   273
         with:  e2 @ ParseErrors{pos: p2 expected: x2 messages: m2}
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   274
.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   275
  Cond [
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   276
    ((p1 > p2) || (empty? e2)) => e1,
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   277
    ((p2 > p1) || (empty? e1)) => e2
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   278
  ] else: ParseErrors{pos: p1
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   279
                      expected: x1 `union` x2
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   280
                      messages: m1 `append` m2}
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   281
).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   282
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   283
bind (-> next results @ ParseResults{next: tvar} .
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   284
  atomic (
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   285
    !tvar -> next.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   286
    if: procedure? next
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   287
      then: ($next () -> next-value.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   288
             tvar := next-value.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   289
             next-value)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   290
      else: next.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   291
  ).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   292
).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   293
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   294
(
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   295
  "This is to parse as 'meta (-> m. ...)'."
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   296
  meta -> m.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   297
  dict at: key ifAbsent: [m `return` false] -> val.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   298
  val
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   299
)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   300
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   301
bind (-> over: list @ Pair{car: a cdr: d}
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   302
         map: block @ (-> _ . _).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   303
      Pair{car: ($block a) cdr: (over: d map: block)}.
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   304
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   305
bind (-> over: list @ Nil{}
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   306
         map: block @ (-> _ . _).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   307
      list).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   308
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   309
bind (-> succ (i @ Integer{}). i + 1).
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   310
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   311
"The pattern (-> p1 . p2) is sugar for Function{pattern: p1 body: p2}"