etng-r2/boot.tng
author Tony Garnock-Jones <tonygarnockjones@gmail.com>
Wed, 16 Jan 2019 17:15:58 +0000
changeset 438 1fe179d53161
parent 279 0a1cc4c2eacb
permissions -rw-r--r--
Add missing primitive implementation for the plain interpreter.
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
     1
namespace s = "http://eighty-twenty.org/etng/r1/ns/stream#";
217
99d5b8250c37 Compile to scheme and evaluate.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     2
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
     3
define raw_callcc fn ->
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
     4
  '%assemble' (fn = fn) { .scheme -> ('call-with-current-continuation'
258
4d06e035b80e Begin adapting evaluator to codegen
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 235
diff changeset
     5
					(lambda (k) ('etng-send' fn (list k)))) };
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
     6
define callcc fn ->
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
     7
  raw_callcc { k -> fn {v -> '%assemble' (v = v, k = k) { .scheme -> (k v) } } };
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
     8
231
7881948bd0a9 Tweak function-extension style
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 230
diff changeset
     9
define extends extension base ->
7881948bd0a9 Tweak function-extension style
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 230
diff changeset
    10
  '%assemble' (extension = extension, base = base) {
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    11
    .scheme -> ('etng-merge-functions' extension base);
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    12
  };
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    13
235
185326ca1c7e Implement "someproxy |as somebehaviour" in boot.tng
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 234
diff changeset
    14
-- (someproxy |as somedelegate) somemessage
185326ca1c7e Implement "someproxy |as somebehaviour" in boot.tng
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 234
diff changeset
    15
define as receiver via message ->
185326ca1c7e Implement "someproxy |as somebehaviour" in boot.tng
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 234
diff changeset
    16
  '%assemble' (receiver = receiver, via = via, message = message) {
258
4d06e035b80e Begin adapting evaluator to codegen
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 235
diff changeset
    17
    -- FIXME: need some form of apply here, now we are n-ary instead of unary!
4d06e035b80e Begin adapting evaluator to codegen
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 235
diff changeset
    18
    .scheme -> ('etng-send*' receiver via (list message))
235
185326ca1c7e Implement "someproxy |as somebehaviour" in boot.tng
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 234
diff changeset
    19
  };
185326ca1c7e Implement "someproxy |as somebehaviour" in boot.tng
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 234
diff changeset
    20
234
10e62e160cb0 Switch from "[]" to "rec {}", and add "rec selfid {}" form
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 231
diff changeset
    21
define :booleanBehaviour = rec {
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    22
  .not -> '%assemble' (x = self) { .scheme -> (not x) };
234
10e62e160cb0 Switch from "[]" to "rec {}", and add "rec selfid {}" form
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 231
diff changeset
    23
};
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    24
234
10e62e160cb0 Switch from "[]" to "rec {}", and add "rec selfid {}" form
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 231
diff changeset
    25
define :falseProxy = :booleanBehaviour |extends {v -> v.:false};
10e62e160cb0 Switch from "[]" to "rec {}", and add "rec selfid {}" form
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 231
diff changeset
    26
define :trueProxy = :booleanBehaviour |extends {v -> v.:true};
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    27
225
3250eeca6813 Move 'case' up nearer the top of boot.tng
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 224
diff changeset
    28
define case x options -> options x;
3250eeca6813 Move 'case' up nearer the top of boot.tng
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 224
diff changeset
    29
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    30
define < = .<;
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    31
define > = .>;
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    32
234
10e62e160cb0 Switch from "[]" to "rec {}", and add "rec selfid {}" form
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 231
diff changeset
    33
define :symbolProxy = rec {
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    34
  msg -> case self {
224
91dca64bb782 Correct flaw in < that stops empty (identity) messages from being built.
Tony Garnock-Jones <tonyg@lshift.net>
parents: 221
diff changeset
    35
	   .< -> :messageAccumulator {receiver -> receiver} msg;
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    36
	   _ -> error("Cannot send message to symbol", msg);
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    37
	 };
234
10e62e160cb0 Switch from "[]" to "rec {}", and add "rec selfid {}" form
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 231
diff changeset
    38
};
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    39
234
10e62e160cb0 Switch from "[]" to "rec {}", and add "rec selfid {}" form
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 231
diff changeset
    40
define :messageAccumulator firstSender -> {
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    41
  .> receiver -> firstSender receiver;
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    42
  secondMsg -> :messageAccumulator {receiver -> firstSender receiver secondMsg};
234
10e62e160cb0 Switch from "[]" to "rec {}", and add "rec selfid {}" form
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 231
diff changeset
    43
};
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    44
226
1ef6bd84451f Add <> as syntactic-sugar for (< >)
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 225
diff changeset
    45
define <> = < >;
1ef6bd84451f Add <> as syntactic-sugar for (< >)
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 225
diff changeset
    46
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    47
define false = '%assemble' () { .scheme -> (not (quote nonfalse)) };
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    48
define true = false.not;
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    49
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    50
define + = .+;
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    51
define * = .*;
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    52
define == = .==;
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    53
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    54
define eq x y -> '%assemble' (x = x, y = y) { .scheme -> ('eq?' x y) };
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    55
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    56
define write x -> '%assemble' (x = x) { .scheme -> (begin (write x) (newline)) };
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    57
234
10e62e160cb0 Switch from "[]" to "rec {}", and add "rec selfid {}" form
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 231
diff changeset
    58
define :eq = rec {
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    59
  .== other -> '%assemble' (a = self, b = other) { .scheme -> ('eqv?' a b) };
234
10e62e160cb0 Switch from "[]" to "rec {}", and add "rec selfid {}" form
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 231
diff changeset
    60
};
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    61
234
10e62e160cb0 Switch from "[]" to "rec {}", and add "rec selfid {}" form
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 231
diff changeset
    62
define :numberProxy = rec {
217
99d5b8250c37 Compile to scheme and evaluate.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    63
  .+ other -> '%assemble' (a = self, b = other) { .scheme -> (+ a b) };
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    64
  .* other -> '%assemble' (a = self, b = other) { .scheme -> (* a b) };
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    65
  .< other -> '%assemble' (a = self, b = other) { .scheme -> (< a b) };
234
10e62e160cb0 Switch from "[]" to "rec {}", and add "rec selfid {}" form
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 231
diff changeset
    66
};
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    67
234
10e62e160cb0 Switch from "[]" to "rec {}", and add "rec selfid {}" form
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 231
diff changeset
    68
define s:empty = { .s:case v -> v.s:empty };
10e62e160cb0 Switch from "[]" to "rec {}", and add "rec selfid {}" form
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 231
diff changeset
    69
define s:cons(head, tail) -> { .s:case v -> v.s:next(head, tail) };
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    70
234
10e62e160cb0 Switch from "[]" to "rec {}", and add "rec selfid {}" form
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 231
diff changeset
    71
define :tupleProxy = rec {
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    72
  .length -> '%assemble' (v = self) { .scheme -> ('vector-length' v) };
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    73
  .get(n) -> '%assemble' (v = self, n = n) { .scheme -> ('vector-ref' v n) };
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    74
  .s:case v -> :tupleIterator(self, 0).s:case v;
234
10e62e160cb0 Switch from "[]" to "rec {}", and add "rec selfid {}" form
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 231
diff changeset
    75
};
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    76
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    77
define :tupleIterator(tuple, index) ->
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    78
  (index < (tuple.length)) {
234
10e62e160cb0 Switch from "[]" to "rec {}", and add "rec selfid {}" form
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 231
diff changeset
    79
    .:true -> {.s:case v -> v.s:next(tuple.get(index), :tupleIterator(tuple, index + 1))};
10e62e160cb0 Switch from "[]" to "rec {}", and add "rec selfid {}" form
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 231
diff changeset
    80
    .:false -> {.s:case v -> v.s:empty};
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    81
  };
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    82
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    83
define s:do stream fn ->
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    84
  stream .s:case {
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    85
    .s:empty -> .ok;
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    86
    .s:next(head, tail) -> do fn(head); s:do tail fn;
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    87
  };
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    88
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    89
define s:foldl stream knil kons ->
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    90
  stream .s:case {
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    91
    .s:empty -> knil;
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    92
    .s:next(head, tail) -> s:foldl tail (kons(head, knil)) kons;
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    93
  };
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    94
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    95
define s:foldr stream knil kons ->
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    96
  stream .s:case {
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    97
    .s:empty -> knil;
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    98
    .s:next(head, tail) -> kons(head, s:foldr tail knil kons);
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
    99
  };
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
   100
228
786b19dd5284 Fix bugs and typo in boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 226
diff changeset
   101
define s:reverse stream -> s:foldl stream s:empty s:cons;
786b19dd5284 Fix bugs and typo in boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 226
diff changeset
   102
define s:append s1 s2 -> s:foldr s1 s2 s:cons;
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
   103
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
   104
define s:foldlK stream knil kons k ->
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
   105
  stream .s:case {
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
   106
    .s:empty -> k(knil);
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
   107
    .s:next(head, tail) -> kons (head, knil) {newSeed -> s:foldlK tail newSeed kons k};
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
   108
  };
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
   109
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
   110
define s:foldrK stream knil kons k ->
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
   111
  stream .s:case {
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
   112
    .s:empty -> k(knil);
228
786b19dd5284 Fix bugs and typo in boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 226
diff changeset
   113
    .s:next(head, tail) -> s:foldrK tail knil kons {newSeed -> kons (head, newSeed) k};
221
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
   114
  };
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
   115
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
   116
define s:concatenate stream -> s:foldr stream s:empty s:append;
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
   117
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
   118
define s:map stream fn -> s:foldr stream s:empty {elt, acc -> s:cons(fn(elt), acc)};
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
   119
eb2506613052 Identifier namespaces, and some interesting code for boot.tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 217
diff changeset
   120
-- s:map (1, 2, 3) {x -> x};
230
70e311e51c29 Add pipe syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 228
diff changeset
   121
-- (1, 2, 3) | s:foldr s:empty s:cons | s:do write;
70e311e51c29 Add pipe syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 228
diff changeset
   122
-- (1, 2) | s:append (3, 4) | s:do write;
70e311e51c29 Add pipe syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 228
diff changeset
   123
-- (| s:append (3, 4) | s:do write) (1, 2);
279
0a1cc4c2eacb Some examples of the new backtracking matcher in operation.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 258
diff changeset
   124
0a1cc4c2eacb Some examples of the new backtracking matcher in operation.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 258
diff changeset
   125
-- define xyz = { .x .y .z -> .w ;
0a1cc4c2eacb Some examples of the new backtracking matcher in operation.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 258
diff changeset
   126
-- 	       .x .y .w -> .a ;
0a1cc4c2eacb Some examples of the new backtracking matcher in operation.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 258
diff changeset
   127
-- 	       .x .a .z -> 345 };
0a1cc4c2eacb Some examples of the new backtracking matcher in operation.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 258
diff changeset
   128
-- define xx = xyz.x;
0a1cc4c2eacb Some examples of the new backtracking matcher in operation.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 258
diff changeset
   129
-- define xy = xx.y;
0a1cc4c2eacb Some examples of the new backtracking matcher in operation.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 258
diff changeset
   130
-- xx (xy (xy.z)) .z;