r3/test-new-syntax.tng
author Tony Garnock-Jones <tonygarnockjones@gmail.com>
Wed, 16 Jan 2019 17:15:58 +0000
changeset 438 1fe179d53161
parent 58 f806c443f183
permissions -rw-r--r--
Add missing primitive implementation for the plain interpreter.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
     1
"Basic idea: all symbols are really variables. They're bound to their
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
     2
underpinning GUID objects. Quoting isn't needed to get literals - it's
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
     3
just convention. Identifiers are not symbols."
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
     4
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
     5
define map [
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
     6
  (_ +f): [(+lp [Hd: +h Tl: +t]) : [Hd: f h Tl: lp t]
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
     7
           (+lp x)               : x]
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
     8
];;
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
     9
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    10
define map [
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    11
  \+f: [(+lp [First: +h Rest: +t] : [First: f h Tl: lp t])
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    12
                \+x: x]]
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    13
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    14
[(_ +x): x]
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    15
[\+x: x]
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    16
\+x: x
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    17
[\+x: x-1]
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    18
\Nil: Nil
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    19
 [Hd: +h Tl: +t]:[Hd: f h Tl: map f t]
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    20
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    21
let diff r1 r2 =
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    22
  let collect [First: +fieldName Rest: +rest] diffs =
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    23
	let v1 = r1 At: fieldName IfAbsent: Absent,
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    24
	    v2 = r2 At: fieldName IfAbsent: Absent,
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    25
	    collect1 +type +old +new =
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    26
	      collect rest [First: [fieldName, type, old, new] Rest: diffs]
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    27
	in cond ((v1 == v2) -> collect rest differences,
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    28
		 (v1 == Absent) -> collect1 Added [] v2,
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    29
		 (v2 == Absent) -> collect1 Removed v1 [],
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    30
		 True -> collect1 Changed v1 v2)
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    31
      collect [] +diffs = diffs
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    32
  in
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    33
    (r1 Class == r2 Class) && collect (r1 Class FieldNames) []
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    34
;;
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    35
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    36
let diff r1 r2 =
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    37
  (r1 Class == r2 Class) &&
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    38
  filterMap [\+fieldName:
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    39
	      let v1 = r1 At: fieldName IfAbsent: Absent,
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    40
		  v2 = r2 At: fieldName IfAbsent: Absent
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    41
	      in cond [(v1 == v2) -> Nothing,
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    42
		       (v1 == Absent) -> [Just: [fieldName, Added, [], v2]]
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    43
		       (v2 == Absent) -> [Just: [fieldName, Removed, v1, []]],
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    44
		       True -> [Just: [fieldName, Changed, v1, v2]]]]
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    45
    (r1 Class FieldNames);;
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    46
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    47
"
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    48
let +a +b = c in d ...
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    49
-->
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    50
[\+a: d ...] [(+a +b): c]
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    51
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    52
let +v = w in x ...
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    53
-->
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    54
[\+v: x ...] w
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    55
"
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    56
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    57
let +diff +r1 +r2 = (r1 Class == r2 Class) &&
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    58
		    filterMap [\+fieldName:
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    59
				let +v1 = r1 At: fieldName IfAbsent: Absent,
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    60
				    +v2 = r2 At: fieldName IfAbsent: Absent
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    61
				in cond [(v1 == v2) -> Nothing,
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    62
					 (v1 == Absent) -> [Just: [fieldName, Added, [], v2]]
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    63
					 (v2 == Absent) -> [Just: [fieldName, Removed, v1, []]],
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    64
					 True -> [Just: [fieldName, Changed, v1, v2]]]]
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    65
			      (r1 Class FieldNames)
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    66
;;
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    67
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    68
let filterMap +fn = [
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    69
   (+loop [First: +f Rest: +r]): maybe (loop r) id (fn f)
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    70
   (+loop x): x
e9fafa149b08 Muck about with yet /another/ experimental syntax
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    71
];;
52
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
    72
56
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    73
"
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    74
Major changes:
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    75
  - identifiers evaluate to the symbol with the same spelling when otherwise unbound
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    76
  - order matters in subsequent pattern clauses. Why did I have it the other way?
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    77
    --> for optional keyword arguments, I think.
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    78
  - you can have expressions in patterns, too. This includes identifier references.
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    79
    What kind of scoping should apply?
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    80
  - since you can have naked identifiers as variable references in patterns, you need
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    81
    some way of introducing a binding occurrence of an identifier. This is, tentatively,
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    82
    spelled +var.
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    83
  - Traits. +, /, @, -
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    84
  - letrec is primitive, since this is a lazy language
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    85
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    86
{} is underused. Could it be used for monad, or letrec syntax?
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    87
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    88
Should we autocurry? (Probably.)
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    89
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    90
_ in value-context means 'top' - ie something that doesn't match
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    91
anything else. _ in binding-context means 'discard'/'bottom' -
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    92
something that matches anything. Actually that's not quite right. You
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    93
can still see _ as equivalent to [], since if it's supplied as a
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    94
value, the only pattern that matches it is [] - and [] as a pattern
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    95
matches any object.
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
    96
58
f806c443f183 Note on free-ness of dot in r3/r4
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 56
diff changeset
    97
Since . is free now, perhaps use it for apply operator? What should
f806c443f183 Note on free-ness of dot in r3/r4
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 56
diff changeset
    98
its precedence and associativity be?
f806c443f183 Note on free-ness of dot in r3/r4
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 56
diff changeset
    99
56
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   100
"
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   101
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   102
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   103
(define (+diff +r1 +r2)
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   104
  (let ((+collect ((First: +fieldName Rest: +rest):
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   105
		     (+diffs:
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   106
		      (let ((+v1 (r1 At: fieldName IfAbsent: Absent))
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   107
			    (+v2 (r2 At: fieldName IfAbsent: Absent))
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   108
			    (+collect1 ((+type +old +new):
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   109
					(collect rest ([fieldName type old new] :: diffs)))))
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   110
			(cond
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   111
			 ((v1 == v2) collect rest differences)
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   112
			 ((v1 == Absent) collect1 Added () v2)
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   113
			 ((v2 == Absent) collect1 Removed v1 ())
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   114
			 (else collect1 Changed v1 v2))))
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   115
		   (): (+diffs: diffs))))
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   116
    ((r1 Class == r2 Class) && collect (r1 Class FieldNames) ())))
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   117
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   118
(define (+diff +r1 +r2)
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   119
  ((r1 Class == r2 Class) &&
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   120
   (filterMap (+fieldName:
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   121
	       (let ((+v1 (r1 At: fieldName IfAbsent: Absent))
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   122
		     (+v2 (r2 At: fieldName IfAbsent: Absent)))
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   123
		 (cond
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   124
		  ((v1 == v2) Nothing)
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   125
		  ((v1 == Absent) Just: [fieldName Added () v2])
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   126
		  ((v2 == Absent) Just: [fieldName Removed v1 ()])
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   127
		  (else Just: [fieldName Changed v1 v2]))))
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   128
	      (r1 Class FieldNames))))
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   129
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   130
(define (+filterMap +fn)
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   131
  ((First: +f Rest: +r): maybe (self r) (+v: v :: self r) id (fn f)
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   132
   +x: x))
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   133
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   134
"
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   135
ThiNG-expressions should be constructed like S-expressions: right-associatively.
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   136
Adjacency and dot, just like sexps, should be equivalent to the reader.
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   137
"
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   138
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   139
{} Length == 0
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   140
{1} Length == 1
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   141
57613e42d98d Merge notes from work and home.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 52
diff changeset
   142
52
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   143
define [diff .r1 .r2]:
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   144
  ((r1 Class == r2 Class) &&
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   145
  filterMap [[_ .fieldName]:
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   146
	     (.v1 <- r1 At: fieldName IfAbsent: Absent,
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   147
	      .v2 <- r2 At: fieldName IfAbsent: Absent,
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   148
	      cond [(v1 == v2) -> Nothing,
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   149
		    (v1 == Absent) -> Just: [fieldName, Added, [], v2],
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   150
		    (v2 == Absent) -> Just: [fieldName, Removed, v1, []],
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   151
		    True -> Just: [fieldName, Changed, v1, v2]])]
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   152
	    (r1 Class FieldNames)
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   153
;;
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   154
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   155
define diff [[_ r1@_ r2@_]:
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   156
	     ((r1 Class == r2 Class) &&
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   157
	      filterMap [[_ fieldName@_]:
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   158
			 v1@_ <- r1 At: fieldName IfAbsent: Absent,
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   159
			 v2@_ <- r2 At: fieldName IfAbsent: Absent,
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   160
			 cond [(v1 == v2) -> Nothing,
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   161
			       (v1 == Absent) -> Just: [fieldName, Added, [], v2],
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   162
			       (v
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   163
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   164
let +diff +r1 +r2 = (r1 Class == r2 Class) &&
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   165
		    filterMap [\+fieldName:
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   166
				let +v1 = r1 At: fieldName IfAbsent: Absent,
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   167
				    +v2 = r2 At: fieldName IfAbsent: Absent
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   168
				in cond [(v1 == v2) -> Nothing,
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   169
					 (v1 == Absent) -> [Just: [fieldName, Added, [], v2]]
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   170
					 (v2 == Absent) -> [Just: [fieldName, Removed, v1, []]],
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   171
					 True -> [Just: [fieldName, Changed, v1, v2]]]]
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   172
			      (r1 Class FieldNames)
e8c6861a3e40 More experimental noise, this time from work's checkout
Tony Garnock-Jones <tonyg@lshift.net>
parents: 51
diff changeset
   173
;;