Learn › Reference › Streams

Contents

Streams

The stream operators relate the positions of a value along one dimension: first, next and fby, and Lucid's wvr, asa and upon, which read a value at the positions where a condition is true. Each entry gives the form, a program with its answers, every rule, and the mistakes with their messages. The examples are read as How to read the examples says.

Along a dimension

Does: these rules hold for all six operators.

Example:

-- file stream-rules.el8
-- Readings kept from t = 3 (the origin of t is still 0), and how fby groups.
reading = input("reading", t : 3 .. 6)
opening = first.t reading
before = 0 fby.t reading
n = 0 fby.t n + 1
steps = 1 fby.t 2 fby.t 3
-- table reading = t,value; 3,30; 4,40; 5,50; 6,60
-- expect opening = eod
-- expect before[t = 3] = eod
-- expect before[t = 4] = 30
-- expect n[t = 2] = 2
-- expect steps[t = 1] = 2
-- expect steps[t = 2] = 3

Open in playground

Answers:

pointwhat is readanswer
openingreading at t = 0, outside its range 3 to 6eod
before at t = 3reading at t = 2, outside its rangeeod
before at t = 4reading at t = 330
n at t = 2n + 1 at t = 1, as 0 fby.t (n + 1)2
steps at t = 12 fby.t 3 at t = 02
steps at t = 22 fby.t 3 at t = 13

Rules:

  1. Each operator names the dimension it moves along, after a dot: first.t e, next.t e, a fby.t b, y wvr.t q, y asa.t q, y upon.t q. Without the dimension, the compiler refuses the program (each entry's Mistakes give the message).

  2. The dimension's coordinates are whole numbers. Along a dimension whose coordinates are texts, the compiler refuses each of the six (for fby: fby, Mistakes, 5).

  3. Every dimension's origin is position 0, whatever bound a value or an input has along it. An input over t : 3 .. 6 is eod at t = 0, so its first.t is eod and fby.t's right operand reads eod at t = 3 (the example).

  4. fby, wvr, asa and upon bind as if … then … else does: more loosely than every other operator except assert and in (Checking what a program assumes, Programs over several files). They group to the right. So in the example, n is 0 fby.t (n + 1), and steps is 1 fby.t (2 fby.t 3):

    n = 0 fby.t n + 1
    steps = 1 fby.t 2 fby.t 3

    From stream-rules.el8.

  5. first.d and next.d are prefixes, and bind as tightly as a minus sign before a number. So rise is (next.t reading) - reading:

    rise = next.t reading - reading

    From next-rise.el8.

first

Why: a value measured against where it started: each reading's change since the first, each price against the opening price.

Does: first.d e is e at d = 0, the same at every coordinate of d.

Form: first.d e, where d is a dimension of whole numbers that e varies along, and e is an expression.

Example:

-- file first-start.el8
-- Each reading's change since the first reading.
reading = input("reading", t : 4)
start = first.t reading
change = reading - first.t reading
at_zero = reading[t = 0]
-- table reading = t,value,ts; 0,20,1000; 1,22,2000; 2,25,3000; 3,21,4000
-- expect start = 20, at time 1000 ms
-- expect start[t = 3] = 20, at time 1000 ms
-- expect change[t = 2] = 5, at time 3000 ms
-- expect change[t = 4] = eod, at time 1000 ms
-- expect at_zero = 20, at time 1000 ms

Open in playground

Answers:

pointreading therestartchangeat_zero
no t20 (at 1000 ms)20 (at 1000 ms)
t = 225 (at 3000 ms)5 (at 3000 ms)
t = 321 (at 4000 ms)20 (at 1000 ms)
t = 4eod: past the boundeod (at 1000 ms)

Rules:

  1. first.d e is e at the context with d set to 0, every other coordinate unchanged.

  2. The result does not vary along d: it has e's dimensions except d. A query may name d or leave it out, with the same answer (start and start[t = 3]).

  3. e must vary along d; otherwise the compiler refuses the program (Mistakes, 2).

  4. eod: where e at d = 0 is eod, the result is eod at every coordinate of d (Along a dimension, rule 3).

  5. Missing data and errors: where e at d = 0 is an error, the result is that error, naming its origin. A reading with no row inside the input's bound is such an error (Results):

    -- file first-gap.el8
    -- No row at t = 0: the first reading is missing.
    reading = input("reading", t : 4)
    start = first.t reading
    -- table reading = t,value,ts; 1,22,2000; 2,25,3000; 3,21,4000
    -- expect start = error missing from reading[t = 0]: input reading has no data at this point

    Open in playground

  6. The timestamp: How operators combine them.

Mistakes:

  1. No dimension. start = first reading gives first works along a dimension, named after a dot: write first.d reading, with d that dimension. Fix: name the dimension, first.t reading.
  2. A dimension e does not vary along. start = first.s reading gives first.s moves along s, but its argument reading does not vary along s: the move has no effect. Fix: name a dimension of reading, first.t.

Each wrong line above is a fragment of a program under Mistake programs.

Neighbours: reading[t = 0] gives the same answer (at_zero; Looking elsewhere). From first-start.el8. For the first position where a condition is true, rather than position 0, asa.

Lineage: first is Lucid's (W. W. Wadge and E. A. Ashcroft, Lucid, the Dataflow Programming Language, Academic Press, 1985), with the dimension named.

Mistake programs
-- file first-no-dimension.el8
-- Mistake 1: first with no dimension.
reading = input("reading", t : 4)
start = first reading
-- expect compile error: first works along a dimension, named after a dot: write first.d reading, with d that dimension
-- file first-other-dimension.el8
-- Mistake 2: first along a dimension its argument does not vary along.
reading = input("reading", t : 4)
start = first.s reading
-- expect compile error: first.s moves along s, but its argument reading does not vary along s: the move has no effect

next

Why: a value compared with the one after it: how much each reading rises by the next, whether the next step is higher.

Does: next.d e is e one position ahead along d.

Form: next.d e, where d is a dimension of whole numbers that e varies along, and e is an expression.

Example:

-- file next-rise.el8
-- How much each reading rises by the next one; there is no row at t = 2.
reading = input("reading", t : 4)
ahead = next.t reading
rise = next.t reading - reading
ahead_too = reading[t = #t + 1]
-- table reading = t,value,ts; 0,20,1000; 1,22,2000; 3,21,4000
-- expect ahead[t = 0] = 22, at time 2000 ms
-- expect ahead[t = 1] = error missing from reading[t = 2]: input reading has no data at this point
-- expect ahead[t = 3] = eod
-- expect rise[t = 0] = 2, at time 2000 ms
-- expect rise[t = 2] = error missing from reading[t = 2]: input reading has no data at this point, at time 4000 ms
-- expect ahead_too[t = 0] = 22, at time 2000 ms

Open in playground

Answers:

treadingaheadriseahead_too
020 (at 1000 ms)22 (at 2000 ms)2 (at 2000 ms)22 (at 2000 ms)
122 (at 2000 ms)Error via reading[t = 2]: missing
2missingError via reading[t = 2]: missing (at 4000 ms)
321 (at 4000 ms)eod: t = 4 is past the bound

Rules:

  1. next.d e at d = c is e at the context with d = c + 1, every other coordinate unchanged.
  2. The result has e's dimensions.
  3. e must vary along d; otherwise the compiler refuses the program with the message of first, Mistakes, 2, naming next.
  4. eod: where c + 1 is past e's bound along d, the result is eod (ahead at t = 3).
  5. Missing data and errors: the result is the outcome of e at c + 1, unchanged (ahead at t = 1). An operator that reads it is strict (Results): rise at t = 2 is the error too.
  6. The timestamp: How operators combine them.
  7. Inside fby's right operand, which is read one step back, next.d e is e at the current position (fby, rule 3).

Mistakes:

  1. No dimension. ahead = next reading gives next works along a dimension, named after a dot: write next.d reading, with d that dimension. Fix: next.t reading.
  2. A value defined from itself one step ahead. x = restrict next.t x + #t to (t : 10) end: no message. Every point reads the point after it, up to the bound, where x is eod, so x is eod at every t. With no bound, a query never reaches a value: it stops at the demand-depth limit with a program error, not an answer. Fix: define a value from the step before, with fby.

Each wrong line above is a fragment of a program under Mistake programs.

Neighbours: reading[t = #t + 1] gives the same answer (ahead_too; Looking elsewhere). From next-rise.el8. To look back one step, fby.

Lineage: next is Lucid's (Wadge and Ashcroft, 1985), with the dimension named.

Mistake programs
-- file next-no-dimension.el8
-- Mistake 1: next with no dimension.
reading = input("reading", t : 4)
ahead = next reading
-- expect compile error: next works along a dimension, named after a dot: write next.d reading, with d that dimension
-- file next-ahead-of-itself.el8
-- Mistake 2: a value defined from itself one step ahead reads up to its bound, and is eod everywhere.
x = restrict next.t x + #t to (t : 10) end
-- expect x[t = 0] = eod
-- expect x[t = 9] = eod

Open in playground

fby

Why: anything that grows step by step: a counter, a running total, a state carried from one step to the next.

Does: a fby.d b ("followed by") is a at d = 0, and at every later position b read one step back.

Form: a fby.d b, where d is a dimension of whole numbers and a and b are expressions; b may name the value being defined.

Example:

-- file fby-total.el8
-- A count of the steps, the running total of the readings, the reading before, and the change since it.
reading = input("reading", t : 4)
n = 0 fby.t n + 1
total = reading fby.t total + next.t reading
previous = 0 fby.t reading
change = error("no reading before t = 0") fby.t next.t reading - reading
back = reading[t = #t - 1]
so_far = sum reading over (t : 0 .. #t) end
-- table reading = t,value,ts; 0,20,1000; 1,22,2000; 2,25,3000; 3,21,4000
-- expect n[t = 3] = 3
-- expect n[t = 50] = 50
-- expect total[t = 0] = 20, at time 1000 ms
-- expect total[t = 1] = 42, at time 2000 ms
-- expect total[t = 3] = 88, at time 4000 ms
-- expect total[t = 4] = eod, at time 4000 ms
-- expect previous[t = 0] = 0
-- expect previous[t = 1] = 20, at time 1000 ms
-- expect change[t = 0] = error raised: no reading before t = 0
-- expect change[t = 1] = 2, at time 2000 ms
-- expect back[t = 0] = eod
-- expect so_far[t = 3] = 88, at time 4000 ms

Open in playground

Answers:

treadingntotalpreviouschangebackso_far
020 (at 1000 ms)20 (at 1000 ms)0Error: no reading before t = 0eod
122 (at 2000 ms)42 (at 2000 ms)20 (at 1000 ms)2 (at 2000 ms)
321 (at 4000 ms)388 (at 4000 ms)88 (at 4000 ms)
4eod: past the boundeod (at 4000 ms)
5050

Rules:

  1. At d = 0, a fby.d b is a at the same context. At d = c, for c > 0, it is b at the context with d = c − 1, every other coordinate unchanged.

  2. Only the operand selected is evaluated: a at d = 0, b at every later position. So change at t = 1 is 2: the error on its left is never evaluated there.

  3. b is read one step back, coordinates included. Inside b, #d is c − 1, next.d e is e at c, and a name is its value at c − 1. So total adds next.t reading: one step back, next gives the reading at the current step.

    total = reading fby.t total + next.t reading

    From fby-total.el8.

  4. A value may name itself in b: it then reads itself one step back, and is an iteration (n, total). A value that depends on itself at the same context is refused before evaluation (Mistakes, 1).

  5. The result varies along d, and along every dimension a and b vary along.

  6. Precedence: Along a dimension, rule 4.

  7. eod: the result is the selected operand's outcome. total at t = 4 is eod, because next.t reading at t = 3 reads past the bound. With no bound written, a value defined with fby has no end: n counts for ever (Values over contexts).

  8. Missing data and errors: the result is the selected operand's outcome (change at t = 0). An error read at one step of an iteration is passed on at every later step, naming its origin:

    -- file fby-gap.el8
    -- A running total over readings with no row at t = 2.
    reading = input("reading", t : 4)
    total = reading fby.t total + next.t reading
    -- table reading = t,value,ts; 0,20,1000; 1,22,2000; 3,21,4000
    -- expect total[t = 1] = 42, at time 2000 ms
    -- expect total[t = 2] = error missing from reading[t = 2]: input reading has no data at this point, at time 2000 ms
    -- expect total[t = 3] = error missing from reading[t = 2]: input reading has no data at this point, at time 4000 ms

    Open in playground

  9. The timestamp: How operators combine them.

Mistakes:

  1. An equation that names itself at the same point. total = total + reading gives unguarded cycle: total -> total (a value cannot depend on itself at the same context). Fix: total = reading fby.t total + next.t reading.
  2. The current reading on the right. wrong = reading fby.t wrong + reading: no message. The right operand is read one step back (rule 3), so it adds the reading before, and wrong at t = 1 is 40, not 42. Fix: next.t reading.
  3. The coordinate on the right. fac = restrict 1 fby.n fac * #n to (n : 20) end: no message. At n = 1 the right operand reads #n as 0, so fac is 0 from n = 1 on. Fix: 1 fby.n fac * (#n + 1), which gives 120 at n = 5.
  4. No dimension. n = 0 fby n + 1 gives fby works along a dimension, named after a dot: write 0 fby.d n, with d that dimension. Fix: 0 fby.t n + 1.
  5. A dimension of texts. s = 0 fby.zone sales, with zone listed as {"north", "east"}, gives zone's coordinates are whole numbers here (fby.zone moves along it), but texts at 3:1 ("north" is listed as a coordinate of zone): a dimension's coordinates are all whole numbers or all texts, so use texts for zone here too, or give the whole numbers a dimension of their own. Fix: move along a dimension of whole numbers.

Each wrong line above is a fragment of a program under Mistake programs.

Neighbours: reading[t = #t - 1] reads one step back too, but is eod at t = 0 (back), where fby gives its left operand (Looking elsewhere). A total of every position so far is also sum reading over (t : 0 .. #t) end (so_far; Regions and aggregates). From fby-total.el8. To read a value at a slower rate, wvr and upon.

Lineage: fby is Lucid's: in Wadge and Ashcroft (1985), the Lucid equation x = 0 fby x + 1 is the counter 0, 1, 2, …. eLucid8 names the dimension, and calls a value defined this way an iteration.

Mistake programs
-- file fby-same-point.el8
-- Mistake 1: an equation that names itself at the same point.
reading = input("reading", t : 4)
total = total + reading
-- expect compile error: unguarded cycle: total -> total (a value cannot depend on itself at the same context)
-- file fby-current-reading.el8
-- Mistake 2: the current reading on the right of fby is read one step back.
reading = input("reading", t : 4)
wrong = reading fby.t wrong + reading
-- table reading = t,value,ts; 0,20,1000; 1,22,2000; 2,25,3000; 3,21,4000
-- expect wrong[t = 1] = 40, at time 1000 ms

Open in playground

-- file fby-coordinate.el8
-- Mistake 3: #n on the right of fby is read one step back too.
fac = restrict 1 fby.n fac * #n to (n : 20) end
good = restrict 1 fby.n good * (#n + 1) to (n : 20) end
-- expect fac[n = 5] = 0
-- expect good[n = 5] = 120

Open in playground

-- file fby-no-dimension.el8
-- Mistake 4: fby with no dimension.
n = 0 fby n + 1
-- expect compile error: fby works along a dimension, named after a dot: write 0 fby.d n, with d that dimension
-- file fby-text-dimension.el8
-- Mistake 5: fby along a dimension of texts.
sales = input("sales", zone : {"north", "east"})
s = 0 fby.zone sales
-- expect compile error: zone's coordinates are whole numbers here (fby.zone moves along it), but texts at 3:1 ("north" is listed as a coordinate of zone)

The walk of wvr, asa and upon

Does: wvr, asa and upon find the positions along d where a condition q is true by a walk, with these rules.

Example:

-- file walk-gaps.el8
-- No row at t = 2 (missing) and an error at t = 4.
q = input("q", t : 8)
y = restrict 100 + #t to (t : 8) end
w = y wvr.t q
u = y upon.t q
p = restrict default(q, false, "missing") to (t : 8) end
w2 = y wvr.t p
-- table q = t,value,ts; 0,false,1000; 1,true,2000; 3,true,4000; 4,error: bad reading,5000; 5,true,6000; 6,false,7000; 7,true,8000
-- expect w[t = 0] = 101, at time 2000 ms
-- expect w[t = 1] = error missing from q[t = 2]: input q has no data at this point, at time 2000 ms
-- expect u[t = 2] = 101, at time 2000 ms
-- expect u[t = 4] = error missing from q[t = 2]: input q has no data at this point, at time 2000 ms
-- expect w2[t = 1] = 103, at time 4000 ms
-- expect w2[t = 2] = error data from q[t = 4]: bad reading, at time 5000 ms

Open in playground

Answers:

pointthe walkanswer
w at t = 0q at 0 false, at 1 true: the first true position is 1101 (at 2000 ms)
w at t = 1q at 2 is missing, before a second true positionError via q[t = 2]: missing (at 2000 ms)
u at t = 2q at 0 and 1: one true position, so y at 1101 (at 2000 ms)
u at t = 4q at 0 to 3: q at 2 is missingError via q[t = 2]: missing (at 2000 ms)
w2 at t = 1p passes over the gap: true at 1 and 3103 (at 4000 ms)
w2 at t = 2p at 4 is the error in the dataError via p ← q[t = 4]: bad reading (at 5000 ms)

Rules:

  1. At a point with coordinate c along d, the walk examines q at positions 0, 1, 2, … along d, in order, every other coordinate as at the point. Each entry says how far it walks and which position it reads y at.

  2. A position where q is true counts; one where q is false is passed over.

  3. An eod in q ends the walk, and the result is eod: the condition's data has ended, so there is no later position to find.

  4. An error in q is the result, naming its origin: the walk cannot know whether that position counts. A missing reading is such an error (w at t = 1). So the first of an eod and an error that the walk meets is the result.

  5. A q that is not a boolean gives the error wvr needs a boolean condition (asa needs …, upon needs …).

  6. Past q's bound along d, the result is eod.

  7. Along a dimension declared inf in an input that q reads, the walk looks only up to the last row along d (Results):

    -- file walk-inf.el8
    -- Readings with no end: the walk stops at the last row along t.
    reading = input("reading", t : inf)
    passed = reading wvr.t reading >= 20
    -- table reading = t,value; 0,18; 1,21; 2,19; 3,24
    -- expect passed[t = 1] = 24
    -- expect passed[t = 2] = eod

    Open in playground

  8. wvr and asa need q bounded along d, or reading an input along d; otherwise the compiler refuses the program (wvr, Mistakes, 1). upon needs neither: it examines only positions before c.

  9. To pass over missing readings rather than stop at them, default(q, false, "missing") (w2; default).

  10. The timestamp: How operators combine them.

wvr

Why: a value read only where a condition holds, renumbered: the readings that passed a check, one after another; the positions of the events.

Does: y wvr.d q ("whenever") at d = c is y at the (c + 1)th position along d where q is true.

Form: y wvr.d q, where d is a dimension of whole numbers, y an expression and q a condition.

Example:

-- file wvr-passed.el8
-- The readings of at least 20, one after another, and where each was.
reading = input("reading", t : 8)
ok = reading >= 20
passed = reading wvr.t ok
position = #t wvr.t ok
-- table reading = t,value,ts; 0,18,1000; 1,21,2000; 2,19,3000; 3,24,4000; 4,22,5000; 5,17,6000; 6,25,7000; 7,16,8000
-- expect passed[t = 0] = 21, at time 2000 ms
-- expect passed[t = 1] = 24, at time 4000 ms
-- expect passed[t = 3] = 25, at time 7000 ms
-- expect passed[t = 4] = eod, at time 8000 ms
-- expect position[t = 2] = 4, at time 5000 ms

Open in playground

Answers:

treadingokpassedposition
018false21 (at 2000 ms)
121true24 (at 4000 ms)
219false4 (at 5000 ms)
324true25 (at 7000 ms)
422trueeod (at 8000 ms): no fifth
517false
625true
716false

Rules:

  1. At d = c, the walk (The walk of wvr, asa and upon) goes on until it has met c + 1 true positions; the result is y at the last of them, s, every other coordinate unchanged.
  2. If the walk passes q's bound first, the result is eod (passed at t = 4: ok is true four times).
  3. The result varies along d.
  4. eod, missing data and errors in q: The walk, rules 3 to 6. In y: the outcome of y at s, unchanged.
  5. The timestamp: How operators combine them.

Mistakes:

  1. A condition with no bound along d. picked = level wvr.t every_third, with every_third = mod(#t, 3) == 0, gives wvr.t searches along t, which has no end, and its condition reads no data along t; bound it: restrict … to (t : n) end. Fix: every_third = restrict mod(#t, 3) == 0 to (t : 20) end.
  2. A condition that is not a boolean. kept = reading wvr.t reading: no compile message; the answer is Error: wvr needs a boolean condition. Fix: a comparison, reading wvr.t reading >= 20.
  3. No dimension. kept = reading wvr ok gives wvr works along a dimension, named after a dot: write reading wvr.d ok, with d that dimension. Fix: reading wvr.t ok.

Each wrong line above is a fragment of a program under Mistake programs.

Neighbours: for the first true position only, asa; to read y more slowly rather than skip its positions, upon. To combine the positions where a condition holds rather than list them, an aggregate with an if filter (Regions and aggregates).

Lineage: wvr ("whenever") is Lucid's (Wadge and Ashcroft, 1985). Where Lucid's wvr waits for ever for a true position that never comes, eLucid8 gives eod past the condition's bound.

Mistake programs
-- file wvr-no-bound.el8
-- Mistake 1: a condition with no bound along t.
level = restrict 10 * #t to (t : 20) end
every_third = mod(#t, 3) == 0
picked = level wvr.t every_third
-- expect compile error: wvr.t searches along t, which has no end, and its condition reads no data along t; bound it: restrict … to (t : n) end
-- file wvr-not-boolean.el8
-- Mistake 2: a condition that is a number.
reading = input("reading", t : 4)
kept = reading wvr.t reading
-- table reading = t,value; 0,18; 1,21; 2,19; 3,24
-- expect kept[t = 0] = error type: wvr needs a boolean condition

Open in playground

-- file wvr-no-dimension.el8
-- Mistake 3: wvr with no dimension.
reading = input("reading", t : 4)
ok = reading >= 20
kept = reading wvr ok
-- expect compile error: wvr works along a dimension, named after a dot: write reading wvr.d ok, with d that dimension

asa

Why: the first time something happens: the first reading above a threshold, the first step of an iteration that is good enough.

Does: y asa.d q ("as soon as") is y at the first position along d where q is true, the same at every coordinate of d.

Form: y asa.d q, where d is a dimension of whole numbers, y an expression and q a condition.

Example:

-- file asa-first-pass.el8
-- The first reading of at least 20, and where it was.
reading = input("reading", t : 8)
ok = reading >= 20
first_ok = reading asa.t ok
where_ok = #t asa.t ok
never = reading asa.t reading > 100
first_ok_too = first.t (reading wvr.t ok)
where_ok_too = min #t over (t : 8) if ok end
-- table reading = t,value,ts; 0,18,1000; 1,21,2000; 2,19,3000; 3,24,4000; 4,22,5000; 5,17,6000; 6,25,7000; 7,16,8000
-- expect first_ok = 21, at time 2000 ms
-- expect first_ok[t = 5] = 21, at time 2000 ms
-- expect where_ok = 1, at time 2000 ms
-- expect never = eod, at time 8000 ms
-- expect first_ok_too = 21, at time 2000 ms
-- expect where_ok_too = 1, at time 8000 ms

Open in playground

Answers:

valuethe walkanswer
first_okok false at 0, true at 121 (at 2000 ms), at every t
where_okthe same1 (at 2000 ms)
neverno reading above 100 at 0 to 7, then past the boundeod (at 8000 ms)
first_ok_toowvr's walk at t = 021 (at 2000 ms)
where_ok_toonot a walk: an aggregate over all eight readings1 (at 8000 ms)

Rules:

  1. y asa.d q is y wvr.d q at d = 0: the walk (The walk of wvr, asa and upon) goes on until the first true position s, and the result is y at s.
  2. The result does not vary along d: it has y's and q's dimensions except d. A query may name d or leave it out, with the same answer (first_ok and first_ok[t = 5]).
  3. If the walk passes q's bound first, the result is eod (never).
  4. eod, missing data and errors in q: The walk, rules 3 to 6. In y: the outcome of y at s, unchanged.
  5. The timestamp: How operators combine them.

Mistakes:

  1. A condition with no bound along d. As for wvr, Mistakes, 1, with asa.t in the message: asa.t searches along t, which has no end, and its condition reads no data along t; bound it: restrict … to (t : n) end.
  2. No dimension. first_ok = reading asa ok gives asa works along a dimension, named after a dot: write reading asa.d ok, with d that dimension. Fix: reading asa.t ok.

Each wrong line above is a fragment of a program under Mistake programs.

Neighbours: first.t (reading wvr.t ok) gives the same answer (first_ok_too). For the position, #t asa.t ok (where_ok), or min #t over (t : 8) if ok end (where_ok_too; Regions and aggregates), which reads every reading and so carries the latest timestamp. From asa-first-pass.el8. For position 0 whatever the condition, first.

Lineage: asa ("as soon as") is Lucid's; Wadge and Ashcroft (1985, p. 71) define y asa q as first(y wvr q).

Mistake programs
-- file asa-no-bound.el8
-- Mistake 1: a condition with no bound along t.
level = restrict 10 * #t to (t : 20) end
every_third = mod(#t, 3) == 0
picked = level asa.t every_third
-- expect compile error: asa.t searches along t, which has no end, and its condition reads no data along t; bound it: restrict … to (t : n) end
-- file asa-no-dimension.el8
-- Mistake 2: asa with no dimension.
reading = input("reading", t : 4)
ok = reading >= 20
first_ok = reading asa ok
-- expect compile error: asa works along a dimension, named after a dot: write reading asa.d ok, with d that dimension

upon

Why: one stream consumed at the pace of another: the task worked on, moving to the next task after each tick where the current one finished.

Does: y upon.d q at d = c is y at the number of positions before c along d where q is true.

Form: y upon.d q, where d is a dimension of whole numbers, y an expression and q a condition.

Example:

-- file upon-tasks.el8
-- The task worked on at each tick: the next one after each tick where the task finished.
task = input("task", t : 8)
finished = input("finished", t : 8)
current = task upon.t finished
done = 0 fby.t done + (if finished then 1 else 0)
by_hand = task[t = done]
-- table task = t,value; 0,101; 1,102; 2,103; 3,104; 4,105; 5,106; 6,107; 7,108
-- table finished = t,value,ts; 0,false,1000; 1,true,2000; 2,false,3000; 3,true,4000; 4,true,5000; 5,false,6000; 6,true,7000; 7,false,8000
-- expect current[t = 0] = 101
-- expect current[t = 1] = 101, at time 1000 ms
-- expect current[t = 2] = 102, at time 2000 ms
-- expect current[t = 4] = 103, at time 4000 ms
-- expect current[t = 5] = 104, at time 5000 ms
-- expect current[t = 8] = 105, at time 8000 ms
-- expect current[t = 9] = eod, at time 8000 ms
-- expect by_hand[t = 5] = 104, at time 5000 ms

Open in playground

Answers:

tfinishedtrue positions before tcurrent
0false0101
1true0101 (at 1000 ms)
2false1102 (at 2000 ms)
4true2103 (at 4000 ms)
5false3104 (at 5000 ms); by_hand the same
8eod: past the bound4105 (at 8000 ms)
9eodneeds finished at 8eod (at 8000 ms)

Rules:

  1. At d = c, the walk (The walk of wvr, asa and upon) examines positions 0 to c − 1 and counts the true positions, m; the result is y at d = m, every other coordinate unchanged. At c = 0 nothing is examined, and the result is y at 0.
  2. So y moves on one position after each position where q is true, and stays where it is after each where q is false.
  3. If the walk would examine a position past q's bound, the result is eod (current at t = 9 needs finished at 8).
  4. upon needs no bound on q: it examines only positions before c.
  5. The result varies along d.
  6. eod, missing data and errors in q: The walk, rules 3 to 5. In y: the outcome of y at m, unchanged.
  7. The timestamp: How operators combine them.

Mistakes:

  1. A condition that is not a boolean. moved = task upon.t task: no compile message; from t = 1 the answer is Error: upon needs a boolean condition. Fix: a condition, task upon.t finished.
  2. No dimension. current = task upon finished gives upon works along a dimension, named after a dot: write task upon.d finished, with d that dimension. Fix: task upon.t finished.

Each wrong line above is a fragment of a program under Mistake programs.

Neighbours: the same count written by hand is done = 0 fby.t done + (if finished then 1 else 0), read by task[t = done] (by_hand). From upon-tasks.el8. To skip y's positions where q is false rather than wait at them, wvr.

Lineage: upon is Lucid's (Wadge and Ashcroft, 1985).

Mistake programs
-- file upon-not-boolean.el8
-- Mistake 1: a condition that is a number.
task = input("task", t : 4)
moved = task upon.t task
-- table task = t,value; 0,101; 1,102; 2,103; 3,104
-- expect moved[t = 0] = 101
-- expect moved[t = 1] = error type: upon needs a boolean condition

Open in playground

-- file upon-no-dimension.el8
-- Mistake 2: upon with no dimension.
task = input("task", t : 4)
finished = input("finished", t : 4)
current = task upon finished
-- expect compile error: upon works along a dimension, named after a dot: write task upon.d finished, with d that dimension