Learn

Contents

eLucid8 Playground Tutorial

The eLucid8 Playground runs the eLucid8 engine entirely in your browser: you write a program, give it data, ask for one value at one point, and see every demand the engine made to answer it. This tutorial teaches the playground itself. The language is covered in the eLucid8 Tutorial, so read that first if fby, next and x[t = 4] are new to you.

Each lesson takes 5–10 minutes and starts from one of the built-in examples. Nothing you do is saved in the playground itself: reloading the page or picking another example starts fresh, and other people with the link have their own separate copy. On the website, signed in, Save stores the program in My programs (see Versions, Undo and Save).

The numbers and messages this tutorial quotes are checked against the engine by a test (packages/evaluator/test/playground-tutorial.test.ts).

Tour of the screen

The page has two columns, each with tabs: on the left, what to compute (the Program tab) and the data it reads (the Data In/Out tab); on the right, the question and its answer, always in view, and under them the Visualize, Trace and Service calls tabs. Drag the line between the columns to make either one wider (or move it with the arrow keys, Home and End); the page remembers it. Tabs move with the arrow keys too. On a phone the site shows the phone viewer instead of the playground (on a screen 760 px wide or less, or a phone held sideways; a tablet gets the playground). The viewer shows finished programs, read-only: a list in two parts, eLucid8 (the examples, in their groups, each with a small picture) and Mine (your entries, once you sign in). Tap one: its answer is at the top and its picture under it, at once from a sketch it keeps and then computed live; tap a cell to ask about it. A row (a value over one dimension, as in The basics) has a cursor: ◀ ▶ and Play move it along the row, asking each point in turn, and the answer follows it. At the bottom, Ask asks for another value or point, Why? shows what the answer depended on, and Program shows the code and its data. Nothing there edits or saves: open the same page on a computer to change a program, and it opens as a copy. Each entry has its own address (/e/heat); Share on eLucid8's entries sends it. A share link (/p/…) opens read-only too, under "A shared program, not an entry: it may change, or not work yet."

Add to my entries…, next to Save on a computer, makes an entry of a finished program: a copy of the program as applied, with its question, its picture as you left it and a title and one line on what it shows. It checks first that the changes are applied, that it compiles, that its question answers and that its picture draws, and that program and data are within 64 KB; any ✗ stops it. The program is saved first if it has changes not saved. Your entries are on My programs (with Open, Add again, which replaces an entry and keeps its link, and Remove), at the end of Examples, and on your phone under Mine; only you can see them, unless you choose Anyone with the link for one on My programs: then anyone with its address can open it without signing in (on a phone in the phone viewer, on a computer as an Entry, read-only until you change it), Share sends it, and it is never listed anywhere. Only me again stops the link working. Changing the program later does not change its entry: add it again. After a new release, an entry that no longer works is marked Needs updating, with the reason, and kept.

The playground asks a program's question as soon as the program is there: an example picked, a link opened, a saved program, a reply to the prompt, or the program edited (once you pause typing for 0.6 seconds and it compiles; until then the last version stays, and Update shows what is wrong). The answer and, on the Visualize tab, the value around it are drawn together, with no button to press; a long computation shows its progress and Stop, and a change stops a computation it replaces. Run query asks again after you change the question. The view then stays open as you ask for other values, step through ticks or change the program.

AreaWhat it holds
Left column, above the tabsExamples menu, labelled "Open an example…" (it comes back to that after each pick): the examples in groups (Start here, Lists, records and sets, Sensors and time, Real time, Operations, Grids and simulation, Data science and ML, Business, Outside services), with 45 examples, then a New group with Empty program and Start from my data; the page opens on The basics. When the column is narrow, the menu has a row of its own above the tabs. On the website the menu is not shown: Examples and New ▾ in the site's header take its place
Program tabA line saying what the program reads and calls, with a link that opens Data In/Out ("Reads data: reading (a table, 10 rows). See or change it in Data In/Out"), then · Cheat sheet, a link that opens it over the editor (on the website, those who can describe a program have a Prompt tab before Program: Lesson 9). Once you have opened Data In/Out, the line is shorter: each name is the link to its card ("Reads data: reading (a table, 10 rows) · Cheat sheet"). When the program has comment lines, the line ends with · Hide comments (17 lines): each run of comment lines becomes one line, --▸ 17 comment lines, so that the equations come first; Show comments brings them all back. Click a --▸ line, or put the cursor inside it and press Enter, to show that run alone. You can edit the equations with comments hidden; the comments stay in the program as they were (Save, Download and share links keep them), and the page remembers the setting, on the phone too. Then the program editor, as tall as the column, with long lines wrapped. The Cheat sheet lists each construct with an example and Insert, which puts the example on a line of its own, after the line the cursor is on, or at the end of the program if you have not clicked in it since it was loaded, and closes the sheet; like any edit to the program, it applies by itself; × or Escape closes it too. Below both left tabs, always in view: Update, then Undo (when there is a version to go back to) or Undo changes (while you have changes not applied), and Changes not applied when it applies; under them, the version line ("Version 1: as the example came"); and a status line for compile errors (with a clickable line number) and notes
Data In/Out tabData sources (data that already exists, which the program reads): one card per source, and Add source. Data services (data made on request, by a program outside eLucid8): a card per data service the program calls, titled with what it answers ("echo · simulated: answers with what it is sent"), with the two times that matter most on the card, Takes and Deadline, and everything else (what it answers, how much its time varies, how often it fails, what to try again, whether to reuse answers) folded under More settings; Add a call; a folded Data services reference. Outputs: one card per output the program names (report = CSV(total)), and Add output, which writes one into the program. The tab shows a dot while a card has changes not applied
Right column, topOn some examples (The basics, Calling a service: an echo, A fraud check that can't wait, Correcting data, Maintenance), a Tour: one line of fixed height, "Tour 3 of 5", the step to do, Show me and Close. Point at the step for why it matters and what you should see. When a step ticks, the line says what you should see now, for a few seconds, then shows the next step. Show me takes you there: it opens the tab the step needs, opens any fold on the way, scrolls to the control, puts the cursor in it and draws a ring round it until you use it; for a step that is a change and then Update, once you have made the change, Show me takes you to Update. Once a tour is done, it names the example to try next. Close puts the tour away; a small link stays at the right of the question row: Tour ✓ · Replay once it is done, Tour · Resume at step 3 if you closed it part-way, Tour · 5 steps if you closed it before the first step. The page remembers this for each example.
Right column, the question"Ask for [value] at t = [4] Run query": the value to ask for (the menu lists names only), one box per dimension, and Run query; at the right end, Hints: on; Running… n s with Stop while a query or view takes more than a moment. Under it, the answer alone ("total[t = 4] is 14"), and on one line under that: Why?, its timestamp ("timestamp 0 ms · what is this?") and the work done ("computed 5 values, read 5 data points")
Visualize tabA row, a grid or a picture of the value around the point, with its controls, and under it what the view computed
Trace tabShow every step at the top, then the Demand tree; pressing Why? opens it. Click a row and it is explained beside the tree (below it on a narrow tab): how it was produced, its result in two columns, Value and Time, and any data service call or alignment record
Service calls tabEvery attempt of every service call the last question made: the value and point that made it, the service, what it was sent, its start and when it answered, and its answer; late and failed calls in red. After a question that made calls, the tab shows how many ("1"), in red when any was late or failed ("1 late", "2 failed")

An edit in the program editor is applied by itself once you pause typing and it compiles. Changing anything on Data In/Out changes nothing until you press Update (or Cmd-Enter, Ctrl-Enter on Windows and Linux, from anywhere in Program or Data In/Out), which also applies a program edit at once: then all of it is compiled and, if it compiles, it becomes the next version, and the answer, the data panel, the value list and the view all refresh. Until then, the card you changed is marked "Changed: press Update (⌘↩) to apply" (Ctrl+Enter on Windows and Linux), Changes not applied shows beside Update, and the line under the answer says the answer is from the version before your changes. Press Run query (or Enter in a coordinate box) to ask for another point; asking for another value keeps the coordinates of the dimensions the two share.

Coordinates you typed stay when an Update keeps the value you asked for. A note an Update adds to the status line, such as "running no longer exists, so the query now asks for x.", stays until your next query.

After each step the page says what you can do next, under the answer: "Next: click another cell to ask for it, or change reading's data and press Update."; after an Update, "Next: press Undo to go back to version 1, or pick another example."; after Why?, how to explore the tree and the view. While a tour shows a step, it is the next step, and that line is not shown.

Hints that fade

The tours, the Next lines and the explanations on Data In/Out are there to teach, and they step back once they have. A Next line stays in full until you have done what it suggests (clicked a cell and pressed Update, pressed Undo, pressed Why?, clicked a row of the tree); after that, the line under the answer ends with · Hint, which shows it again for that answer. The line above the editor drops "See or change it in Data In/Out" once you have opened Data In/Out. Nothing shrinks before you have used it, and nothing goes without a way back.

Hints: on, at the right end of the question row, turns them all off at once: tours and their links, Next lines, and the explanations on Data In/Out. Answers, errors, Why?, Undo, the version line, "Changes not applied", the Cheat sheet and its link always show. Hints: off brings everything back in one click: a finished tour as Tour ✓ · Replay, a Next line you have used as · Hint. The page remembers the setting, the tours you finished or closed and what you have used, in this browser (on the website, the site keeps it for the playground).

Queries and views run in the background, so the page stays usable however long they take. When one takes more than a moment, Running… n s appears over the bottom of the question with a Stop button, and on the Visualize tab the picture dims a little under a small turning ring that says what is being computed ("Computing v[x = 48, y = 48, time = 3000]…"; with reduced motion, the ring stands still), until the answer and the picture arrive. Nothing on the page moves to make room for either. Stop ends it at once and restarts the engine, which forgets the values it remembered from earlier queries; the next query computes everything again. (Where the browser does not allow a background engine, queries run on the page itself: the page says so as soon as a query starts, and waits until it ends, without Stop.)

Versions, Undo and Save

A version is everything that can change an answer: the program, every source's data (whether it is a table, a formula or an example's built-in data, and its text), and the data services' settings. Each successful Update is a new version, and the version line under Update says what it is: "Version 2: echo's settings changed (version 1 was as the example came)", or later "Version 3: reading's data changed (Undo goes back to version 2)". Loading an example, a saved program or a shared link starts at version 1 ("as the example came", "as it was saved"). The playground keeps up to 50 versions while the page is open, and forgets them when you reload it.

Undo, beside Update, does one thing at a time. While you have changes not applied, it is Undo changes: it puts back the program, data and settings of the current version, exactly as they were (a table you switched to a formula comes back character for character). With no changes, it is Undo: it goes back to the version before, and applies it.

If the program, or a formula, does not compile, the status line shows the error ("Line 4, column 9: …", with a clickable line number), and the answer and the view stay those of the last version that worked; the status line says so, and that Undo changes returns to it. Update stays enabled until you fix it.

On the website, Examples and New ▾ are in the site's header, beside With your agent, Learn, Play and Download, and a bar under it names the program you are in, with a label that says whose it is: Example (one of eLucid8's, or a Learn page's), Shared (someone's program by its link) or Entry (an entry by its link) are read-only; Draft is a program of yours not saved yet; My program is one saved in My programs. Ask for values, press Why? and Play as much as you like: the program stays an Example. Your first change to the program, its data or its settings (a keystroke is enough, before Update) makes it a Draft, titled "(my version)", and the example itself never changes; Undo back to version 1 makes it the Example again, and Reset to example puts the example back (with Undo for 10 seconds). Drafts are kept in this browser, up to 10, and never sent to the site: choosing another example asks nothing, and the note "Your draft … is kept in this browser" offers it back; Examples lists them first. The bar holds the program's actions and Feedback on this program, and the playground below fills the window.

Save as my program always makes a new program in My programs, so an example, a shared program or an entry is never written over: it opens a field with the name it will have ("Heat diffusion over time and space (my version)", numbered if you already have one), and saves under it. Signed out, it is Save as my program ▾: sign in (you come back to the same draft, its name field open), Copy a link to this draft (the program and its data travel in the link; nothing is stored), or Save as file (the program's text). On My program, Save writes your changes over it, and More holds its title, who can see it, its description, Save as new and Download. Download needs no Save first: the program downloads as the playground shows it (its changes applied first, as Save applies them). Saving stores the last version that compiled, with its data and settings, so a saved program is always one that ran. If you have changes not applied, it applies them first, as Update does, and saves only if they compile; otherwise it shows the compile error and saves nothing. Once saved, the website says "Saved to My programs." After a change to My program that you have not saved, even one to data or settings, the website shows Not saved.

On the website, Examples opens the same list, with a search field first ("heat", "missing data", "forecast") and your drafts in this browser before it: choosing an example opens it as an Example, at version 1, with its data and query, at its own address (/e/heat). New ▾ starts a program of your own, a Draft: Empty program ("Untitled program"), Describe it in words (where the program writer is available) or Start from my data. A Learn page's Open in playground opens its example as an Example, with "From the Tutorial, §1 · Back to the Tutorial" in the bar; a program from a chat's link opens as a Draft "From a link". Escape or Close closes Examples and changes nothing.

Start from my data

Start from my data, under New ▾ (and in the Examples menu's New group when the playground is open on its own), starts a program from your own files. It asks three things, one step at a time:

A file larger than a saved program may hold (64 KB of program and data) runs in the playground, but Save keeps the program without the file's rows; its card then says to load the file again.

Lesson 1: Run your first query

You will ask for the running sum of a six-number stream and get 14.

  1. Choose Streams: first, next, fby from Examples. The program is written in the language's notation v0.2, as every example is. x = input("x", t : 6) is the data source x, data that already exists (Where data comes from and where it goes), bounded to its six readings, t = 0 to 5, and there are four values: n, running, delta and since_start.
  2. Open the Data In/Out tab and look at the card data source x. It is a table: t,value then the rows 0,3 · 1,1 · 2,4 · 3,1 · 4,5 · 5,9.
  3. On the right, the question reads "Ask for running at t = 4", and under it, asked as the example opened: "running[t = 4] is 14" (3 + 1 + 4 + 1 + 5), and on the Visualize tab, running over t, with its line chart.
  4. On the line under the answer: Why?, the answer's timestamp, and the work done: how many values were computed, whether the answer was reused from an earlier question, how many data points were read, and how many service calls were made. A count that is 0 is left out. A large view (4,096 cells or more, such as the 96 × 96 dish of Reaction–diffusion: coral from a square) is computed first, and the answer taken from it, so that the same work is not done twice: the line then says "computed … values for the answer and its view". Numbers are shown with up to six significant digits (0.0026693, 1.1195, 2/3 as 0.666667), whole numbers whole; point at an answer or a cell for the number in full, and the trace's details give it too.
  5. Change t to 5 and press Enter: 23. Change it to 6: eod (no data), because next.t x at t = 5 asks for x[t = 6], beyond its six readings.

Try the other values at t = 4: delta is 4 (9 − 5), since_start is 2 (5 − 3) and n is 4.

Lesson 2: Read the demand tree

The demand tree shows every value the engine asked for to answer your query, nested under whatever asked for it. Run query gives the answer alone, which keeps big queries fast; Why? beside the answer gives its tree.

  1. Stay on Streams with running at t = 4, asked. On the Trace tab you will see "Press Why? beside an answer to see what it depended on." Press Why? under the answer: the tab opens.
  2. The same query runs again from scratch, so the tree shows the whole computation (values remembered for later queries are kept).
  3. The root row is running at t = 4. Each row shows the point asked for, a coloured label saying how it was produced, and → its outcome. The first three levels open automatically; click ▸ to open deeper ones.
  4. Under the root you will find running at t = 3 (the fby step back) and x at t = 4 labelled read. Follow running down to t = 0 to see the whole iteration.
  5. Click any row: beside the tree, it names the row, explains its label in one sentence and shows its result under Value and Time (here 14 and 0).
  6. Press Run query again without changing anything. The line under the answer says "reused from an earlier question": it was computed by the first query (Lesson 4).

Views: rows, grids and Play

Two dimensions make the picture, one may be played, the rest are held. Each view says which in one line under it: heat: a stream of x × y pictures along time.

The Visualize tab shows the queried value around your point, drawn with the answer, by itself when the program opens or changes and again when you press Run query: one cell per coordinate, coloured by its answer. Click a cell to query it. It stays open as you ask for other values or press Update. A view too large to draw at once (more than 65,536 cells, or more than 16 for a value in a program that calls a data service, so that a view never sends many calls you did not ask for) waits for Draw it: "density over x × y is 400 × 400 cells. Draw it". The whole view is asked for together, which gives each cell exactly what asking for it alone gives, and computes each step of an iteration once for the whole board. Views of a value that calls a data service are asked for one cell at a time. The line under the picture says which, and counts the work.

On Heat diffusion over time and space, once the picture is drawn (by itself), press Play under it to watch the heat spread tick by tick. Play runs from the start on to the example's end (Life's 300 generations, heat's 400 ticks; elsewhere the larger of the queried tick and 100 ticks), a frame every 50 ms (about 20 a second) where each is computed in time; a longer run is shown in at most 400 frames, each a few ticks on, so Reaction–diffusion: coral from a square, asked at time 3000, plays in frames of 8 ticks. While it plays, the colour scale holds still (it only widens), so the plate visibly cools as the heat spreads. With Mark on the picture ticked, Play keeps a slower pace, 450 ms a frame, to watch the marked cells. The played dimension starts at the queried tick; ◀ and ▶ move it one step, the box between them is the tick shown (type one and press Enter), and the slider under them goes straight to a tick. Then in View ▸, pick time for the picture's up side and set Plays along to nothing: heat: an x × time picture, at y = 64, the plate's middle row through time.

A value with two small dimensions and no steps (at most 16 coordinates each), such as the matrix example's C, is a table: its first dimension down the rows, its second across the columns, each cell with its number. A grid over a dimension of texts, such as sales planning's products and zones, is a table too.

Lesson 3: Write your own program and give it data

Every source you declare gets a data box, and you choose how it supplies values.

Start from any example and replace the program with this; it is applied by itself once you stop typing:

temp = input("temp", t : 4)

change = next.t temp - temp
warming = change > 0
  1. The version line should read "Version 2: the program changed (version 1 was as the example came)". If the status line shows a compile error instead, click the line number in the message to jump to the problem.
  2. A source temp card appears with the header t,value. Add the rows 0,10 · 1,12 · 2,11 · 3,15, one per line, and press Update: "Version 3: temp's data changed".
  3. Ask for warming at t = 2 and press Run query: "warming[t = 2] is true" (15 − 11 = 4). At t = 3 it is eod, because temp ends at t = 3 (its bound, t : 4), so next.t temp has nothing there.
  4. Switch the card's mode from table (CSV) to formula. It starts with a formula that works, #t * 10 (for a table of only 0s and 1s, such as a board, if #t < 3 then 1 else 0), and the line under it explains: "Each point's value from its coordinates, for example #t * 10 or if #t < 3 then 1 else 0." Replace it with 10 + #t * 0.5 and press Update. Now every t from 0 to 3 has a value, so change is 0.5 at t = 0, 1 and 2 (and still eod[t = 3]).
  5. Press Undo twice: once to version 3 (the table), then to version 2 (no rows). Switching to the formula and back before an Update finds your table again; Undo changes puts it back too.

The three data modes:

ModeWhat you typePoints with no data
table (CSV)A header of the source's dimensions plus value, then one row per point. Values can be numbers, true/false, eod (end of data) or error: message. A quoted field ("a, b", with "" for a quote) is always text; read exactly as the elucid8 command reads a CSV file. A ts column, if there is one, holds each row's timestamp in millisecondseod
formulaOne eLucid8 expression using #t, #x and so onNone: every point has a value
built-in exampleNothing; offered only where an example supplies its own function (the Alps data, the Game of Life seed)Decided by that function

Values computed before an Update or a data edit are reused only where nothing they depend on has changed.

Lesson 4: Reusing earlier answers

The playground remembers every value it computes, so later queries reuse earlier work. A remembered value is reused only while nothing it depends on has changed: not its equation, and not the data it read.

  1. Load Streams: first, next, fby again: it is asked by itself, running at t = 4 is 14, and the line under it says "computed 5 values, read 5 data points".
  2. Query t = 5: 23, "computed 1 value, read 1 data point": running at t = 4, and everything before it, were reused from the first query.
  3. Edit source x, changing the first row to 0,4, and press Update: the answer becomes 24, "computed 6 values", because every value read the old first row.
  4. Press Run query again: "reused from an earlier question".

In a tree (Why?), a value reused from an earlier query is labelled reused; within one query, a value asked for twice is computed once, and the second time it is labelled already computed.

Lesson 5: Service calls, deadlines and late

A data source is data that already exists, which the program reads: a table, a file, a database. A data service is data made on request: at each point the program asks an outside program, such as an AI model or a web API, and the answer is data stamped with the time it arrived. Where data comes from and where it goes says more about both, and about outputs. In the program both are inputs: echo = input("echo", n : inf) is an input whose values a program answers on demand, and answer = echo[n = reading] sends reading at each point to echo and takes its answer. Whether an input's values are stored or answered on demand is its card's choice, under Inputs on Data In/Out, not the program's. An outside program may be slow, or fail. Its deadline (how long its answer may take), which failures to try again and whether to reuse answers are the input's settings, on its card, not part of the program. An answer that comes after the deadline is late: an error, which you see, never a number made up in its place.

Choose Calling a service: an echo (in Outside services). echo is the simplest data service there is: it answers with what it is sent, 5 ms later, with a 20 ms deadline. A Tour above the question goes through it a step at a time, and ticks each step as you do it; Show me takes you to the place each step needs:

  1. Asked as the example opened: "answer[t = 2] is 20", with timestamp 5 ms. echo was sent reading at t = 2, which is 20, and sent it back. The Service calls tab shows 1. Press Run query, as the Tour's first step asks: echo is called again (its answers are reused only when its settings say so), with the same answer, and the tab still shows 1.
  2. Open the Service calls tab: one call, echo, sent [20], started at 0 and answered at 5 ms.
  3. Make echo take 30 ms, longer than its 20 ms deadline: on echo's card (Data In/Out), set Takes to 30. The card is marked as changed.
  4. Press Update: "answer[t = 2] is late", and under it, in plain words, "echo answered after 30 ms, past its 20 ms deadline." The Service calls tab shows "1 late", in red, and the version line reads "Version 2: echo's settings changed (version 1 was as the example came)".
  5. Press Undo, beside Update: back to version 1, where echo takes 5 ms, and the answer is 20.

When the answer matters: a fraud check that can't wait. Choose A fraud check that can't wait. An AI model, fraud_model (simulated), scores each card payment for risk; a payment must be decided within 200 ms, and when the model is late or fails, a rule decides instead (approve under 500):

payments = input("payments", t : 8)
fraud_model = input("fraud_model", amount : inf)
risk = fraud_model[amount = payments]
approve = if iserror(risk) then payments < 500 else risk < 70

approve at t = 1 is false: the model was too slow for the payment of 1250 (ask for risk at t = 1: "risk[t = 1] is late", and under it "fraud_model answered after 257 ms, past its 200 ms deadline."), so the rule rejected it. At t = 6 the model failed ("risk[t = 6] is an error", and under it "fraud_model answered with an error (overloaded).") and the rule approved 310. Ask for approve at t = 6 and press Why?, then click approve in the tree: beside it, the trace says "risk[t = 6] is an error (service error: overloaded), and approve[t = 6] is still a value: its equation tested for the error and took the branch that reads payments[t = 6]." On fraud_model's card, set Deadline to 300 ms and press Update: no answer is late any more, and approve at t = 1 follows the model (risk 37: approved).

Your own program, with retries. Start from any example and replace the program with this:

x = input("x", t : 4)

sum_service = input("sum_service", n : inf)

total = sum_service[n = x]

alarm = total > 15
  1. Once the program is applied (by itself, when you stop typing), switch the input "x" card to formula, enter 10 * #t and press Update. The input sum_service has no data, and its channel is the playground's stand-in, so its card under Inputs says that sum_service answers it on demand ("sum_service, answering on demand" in its menu): "sum_service answers the sum of the point's coordinates", with Takes 5 ms. Set Deadline to 20 ms. Open More settings: set Try again on overloaded up to 2 attempts in all, and press Update ("Version 4: sum_service's settings changed").

  2. Query total at t = 2: 20, with timestamp 5 ms. A call starts at the latest timestamp of its inputs; the formula's data carry none, so it starts at 0 ms and answers at 5 ms, inside its 20 ms deadline, and the answer is stamped with that time. Press Why? and click the call in the tree, the row sum_service[n = 20], and read the Data service call table beside it: the deadline, each attempt's start and finish, and the result. There is one attempt.

  3. Query alarm at t = 2: true (20 > 15).

  4. Set Takes to 30 and press Update: the delay is part of the version ("Version 5: input sum_service's settings changed"), and total is asked for again: "total[t = 2] is late". alarm at t = 2 is now "Error via total ← sum_service[n = 20]: late (30 ms > deadline 20 ms)": the lateness is passed on, never replaced by an ordinary answer.

  5. The retry setting allows a second attempt when the service fails with the error code overloaded, before the deadline. sum_service never fails, so the table still shows one attempt: a late answer is not retried.

  6. On the Visualize tab, total over t: with the delay at 30, all four cells are purple (late). Press Undo (the delay back at 5, version 4) and they show 0, 10, 20 and 30.

  7. Open the Service calls tab: the last question's call, its start and completion, and its answer, in red when it was late.

Two services, two deadlines. A program's settings belong to its input, so to give one call a longer deadline than another, read two inputs. Add these two lines to the program; they are applied by itself once you stop typing:

quick_sum = input("quick_sum", n : inf)
quick = quick_sum[n = x]

quick_sum has no data yet: its card offers a table. Choose a simulated program, answering on demand in its menu instead. A simulated program answers a sum, a score or a formula, optionally with a delay and a failure rate: the sum, mean or largest of the coordinates it is asked at, a score from 0 to 100, or a formula over them (x1 * 2 + x2); a delay fixed, or varying between two values; failures from 0% to 50% of attempts, with an error code. A new one answers the sum after 5 ms and never fails. Its times and failures come from what it is asked, so the same question always gives the same answer. Set its answer to the largest (under More settings) and its Deadline to 2 ms, press Update, and query quick at t = 2: "quick[t = 2] is late", and under it "quick_sum answered after 5 ms, past its 2 ms deadline.", while total keeps its own deadline. In a deployment, the two inputs are two entries in deploy.json, which may be answered by the same real program.

An input is answered on demand only when its card says so: by sum_service, the playground's stand-in, or by a simulated program you set up. The Services reference describes them. Misspell the stand-in's name, input("sum_servce", n : inf), and the input is just one with no data: its card offers a table, and total is an error saying so, input "sum_servce" has no data: give it rows, or a provider that answers it, until you give it data or choose a program that answers it.

A call on a stream with timestamps. A call starts at the time of the data it is given (the latest timestamp of its inputs), and the deadline counts from there. The data's own times come in through a table's ts column, and two streams at different rates meet through them (Lesson 6 explains asof, hold and window in full). Here a reading every 100 ms is multiplied by the latest calibration at or before its time, and the result is sent to the service:

reading = input("reading", s : 4)
calibration = input("calibration", c : 3)

calibrated = reading * asof.c calibration at time(reading) end

sum_service = input("sum_service", n : inf)

total = sum_service[n = calibrated]

Once the program is applied (by itself, when you stop typing), give reading the table s,value,ts with rows 0,10,0 · 1,11,100 · 2,12,200 · 3,13,300, and calibration the table c,value,ts with rows 0,1,0 · 1,2,150 · 2,3,250, and press Update. Keep the service's deadline at 20 ms.

  1. Query calibrated at s = 2: 24, with timestamp 200 ms (12 × 2: at 200 ms the latest calibration is the one from 150 ms). total at s = 2 is 24 too, with timestamp 205 ms: the call starts at 200 ms, the time of the data it is given, and answers 5 ms later.
  2. Replace asof.c calibration at time(reading) end with hold.c calibration at time(reading) within 40 end; once you stop typing it is applied, and calibrated at s = 2 is now missing data (an error of kind missing), because the latest calibration is 50 ms old, more than the 40 ms allowed, and a later one follows at 250 ms. total at s = 2 is that error as well: the service is not called with an error.
  3. Use mean calibration over (c : window.c 200 at time(reading)) end instead: at s = 3 (300 ms) it is 32.5, 13 times the mean of the calibrations from 150 and 250 ms.
  4. Set Takes to 30 on sum_service's card and press Update: every call with an answer is late. At s = 2 the call starts at 200 ms and answers at 230 ms, after its deadline at 220 ms. The answer reads "total[s = 2] is late", stamped 220 ms, and its row in the trace says "late: answered at 230 ms, after its deadline at 220 ms".

Lesson 6: Align two streams by time

In the v0.2 notation, data can carry timestamps: each value is its data and a time in milliseconds. The playground shows a value's timestamp under its answer ("timestamp 390 ms") and in the trace; Timestamps says more. Two streams at different rates meet through their timestamps: asof.d(v, T), hold.d(v, T, max) and window.d(v, T, w) choose values of v along d by their timestamps, and time(e) reads the timestamp of e.

Choose Two streams and alignment by time. A reading arrives at 0, 98, 203, 300, 390, 401 and 499 ms (time_s 0 to 6) and is multiplied by a calibration from 0, 230, 380 and 401 ms (time_c 0 to 3). Both are tables whose ts column holds each row's timestamp. The calibration table is 1.0, 1.05, an empty cell, 1.1: the calibration at 380 ms did not come, so it is missing data (an error of kind missing, at its row's time). asof takes the latest calibration whatever it is, so where that is the missing one, the answer is its error; hold writes skip missing, and steps back over it; a mean over a window leaves it out, and the answer warns how many points it left out.

time_s (reading's time, ms)asofhold, less than 100 ms old, skip missingwindow, 200 ms (mean)
1 (98)111111
2 (203)12Error: hold: no data within 100 ms before 203 (missing: the latest calibration is 203 ms old, and the next comes at 230 ms)Error: mean of no elements (no calibration in the window)
3 (300)13.6513.6513.65
4 (390)Error via calibration[time_c = 2]: the calibration at 380 ms is missingError: hold: no data within 100 ms before 390 (missing: past the missing one, 1.05 is 160 ms old, and 1.1 comes at 401 ms)14.7: the missing one left out, with "Warning: aggregates left out 1 missing point of input calibration"
5 (401)16.516.516.125: mean of 1.05 and 1.1
  1. Query each of the three values at time_s 1 to 5 and compare with the table.
  2. Press Why? beside any answer and open its tree: it lists the reading and every calibration row the alignment examined; click a row to see its timestamp beside the tree.
  3. Edit a ts cell or the calibration table, press Update, and watch the answers change. Lesson 4 applies: every value that read the old data is computed again.

Timestamps

Every value has a timestamp: the time of the latest data it was computed from, in milliseconds since 1970 (0 when nothing it read carries a time). The line under the answer always shows it ("timestamp 0 ms · what is this?"), and the trace shows it for the row you select.

Lesson 7: Show every step

The playground computes values that iterate along a dimension, such as heat over time or a network's weights over training steps, a whole step at a time: fast, but the demand tree then shows each step as one row. Show every step, at the top of the Trace tab, computes one value at a time instead, so the tree shows every value being asked for. The answer is the same either way; off is faster on large grids.

  1. Choose Heat diffusion over time and space, set time to 5 and x to 40, and press Run query: heat at time 5, x 40, y 64 is 26.9136, near the edge of the hotter disc.
  2. Press Why?. The tree has 6 rows: the answer, labelled computed together because each step of the plate was computed at once, then one row for each earlier step, naming the cells of the plate computed at that step.
  3. Tick Show every step: the query is asked again, with its tree. The answer is still 26.9136, but the tree now has 1607 rows: every value of the light cone is computed one at a time (286 values), from the 121 data points it reads.
  4. Tick Mark on the view, after Why? beside the answer: the marks are the same with Show every step on or off.

Click a step's row: its details explain the step and offer Show every step for the value asked about, which asks for it again with the full tree, every value one at a time. On Heat diffusion over time and space, showing the whole plate at time 20 takes a fraction of a second with Show every step off and a few seconds with it on.

Lesson 8: Missing data, errors and program mistakes

An answer is a value, eod (end of data: the point is past the data) or an Error, and every Error names the point where it started. Missing data is an Error of kind missing: a reading that should be there and is not. Choose Missing and failed readings (missing data and errors): reading's table has an empty cell at hour 5 (the reading did not come: missing data) and error: sensor fault at hour 9 (the sensor reported a fault).

QueryAnswerWhy
doubled at t = 5Error via reading[t = 5]: input reading has no data at this pointStrict: missing data is an Error, passed on like any other
doubled at t = 9Error via reading[t = 9]: sensor faultThe Error names the point where it started: the input reading (day is that input, over one day)
safe at t = 90The guard is false, so the bad reading is never asked for
window3 at t = 633, with "Warning: aggregates left out 1 missing point of input reading"An aggregate leaves missing data out, and says how many points it left out: 16 + 17, hours 6 and 7
window3 at t = 10Error via reading[t = 9]: sensor faultAny other Error is kept: the window t 9–11 reaches the fault
change at t = 0eodHour 0 has no hour before it: past the data, not a gap

Then empty hour 9's cell in reading's table and press Update: hour 9 is missing too, and window3 at t = 10 is 41 (20 + 21), with the warning. The same hour, missing rather than failed, is left out instead of passed on. To give a missing reading a value of your own, write default(day, 0, "missing"); to say that the gaps are expected and need no warning, sum day over (t : #t - 1 .. #t + 1) skip missing end.

The playground catches three kinds of program mistake:

If a query ever stops with "Stopped: the engine broke one of its own rules", that is a fault in eLucid8, not in your program: report it with the program and the query that caused it.

Lesson 9: Describe what you want to compute

On elucid8-lang.org, signed in with an account that has it (for now, the eLucid8 reviewers), the left column has three tabs, Prompt, Program and Data In/Out. Prompt holds a box, Describe what you want to compute, as tall as your description. Under it, one line says how to ask: "Say what the data is (or none), what to compute, and what you want to see."; the box shows an example in that order, changing every few seconds until you click in it. Under that line, four chips (Try: Mandelbrot you can zoom, Sales, 7-day average, Heat on a plate, Life from a random seed) each put a whole description in the box, which you can edit; nothing is sent until you press the button. Write what you want in plain words and press Generate and run program: an AI writes the program in eLucid8. Once the program is your own (you changed it, saved it, opened it from a link, or it was written from a description), the button is followed by or change the current program, which changes it instead. Being on Prompt pauses a tour ("Tour paused · Resume at step 1"). ⌘↩ in the box writes a new program, or a change when your description starts with "Change:". × in the box empties it. The box writes programs only: anything else is answered with a card, "This box writes programs that compute something.", a link to the Learn page that fits (the Quick reference for a question about eLucid8), and, where one fits, the request reworded as a computation, which Put this in the box puts in the box. The playground on its own, outside the site, has no box.

Examples to describe. Under the box on Prompt, a fold, More examples to describe · and how to describe a program, opens the list of ready-made descriptions: one on real data (the European Central Bank's euro–dollar rates, which the page fills in instead of made-up data), ten new programs from simple to complex, a folded group From science, engineering, history and AI (simplified models, for learning), and changes, each shown only with the program it fits. Each is written in five parts, a line each: Data, Compute, Show, Check and Output; How to describe a program, at the top of the list, says what goes in each. Generate and run this program (for a change, Generate and run this change) writes it at once, its description put in the box so that you can change it and write it again. If it replaced your own text, Put back your description restores it. The ready-made descriptions are answered with programs the AI wrote for them earlier, so trying them costs nothing; any edit to the description writes a new one. Prompts 8 and 9 bring in a file of your own; beside them, sales.csv to try it with saves a 14-day example file (north's last 7-day average is 17, south's 10.4286). At the foot of the list, Cheat sheet opens the code constructs over the editor.

Your description, and for a change your program and a few rows of your data, are sent to Anthropic to write the program: the Privacy page says what is sent and kept. Tick Share my description to help improve this, under the box, to let the eLucid8 team keep that description and the program written for it; unticked, nothing is kept. Each account has 10 requests a day. The AI can write a wrong program: check the answer it names by hand, and read the program before you rely on it.

Quick reference

Controls

ControlDefaultEffect
Run queryAsks the question: the answer, and the view around it
Update (Cmd-Enter or Ctrl-Enter anywhere in Program or Data In/Out)disabled until you change somethingCompiles the program with its data and settings; if it compiles, it becomes the next version and everything refreshes
Undo changesshown while you have changes not appliedPuts back the program, data and settings of the current version
Undoshown, beside Update, when there is a version to go back toGoes back to the version before
Show me (in a tour)Takes you to the step's control: its tab, open, scrolled to, focused and ringed
Hints: on / off (right end of the question row)onOff hides tours, Next lines and the explanations on Data In/Out; on brings them back
Tour ✓ · Replay, Tour · Resume at step n (question row)shown once a tour is done or closedOpens the tour again, at its first step or where you left it
· Hint (under an answer)shown once you have done what its Next line suggestsShows that answer's Next line in full
Why? (under an answer, and beside a step in the trace)Asks for the same point again from scratch, with its demand tree; an open view marks the cells it depended on
Show values | timestamps (in a view)valuesDraws each cell's value, or its timestamp
Show every step (top of the Trace tab)offComputes one value at a time, so the tree shows every value asked for; the answer is the same
Generate and run program / or change the current program (the Prompt tab, on the website)the change link once the program is your ownAsks the AI to write a program, or to change this one; what works is applied at once as the next version, its question asked and its picture drawn
× (in the box)shown with text in the boxEmpties the box and clears the last attempt; the program is unchanged
· Cheat sheet (line above the editor)Opens the code constructs over the editor, with Insert
· Hide comments / · Show comments (line above the editor)Folds each run of comment lines into one --▸ line, or shows them all
Generate and run this program (Examples to describe, the Prompt tab)Writes a ready-made description at once

Demand tree labels

LabelMeaning
computedComputed from its equation
computed togetherComputed with the other values of its step, at once
computed with neighboursComputed together with the points around it
readRead from the program's data
read alreadyRead earlier in this query
read beforeRead by an earlier query; the data has not changed
reusedComputed by an earlier query; nothing it depends on has changed
already computedThe same value earlier in this query
service calledA data service was called
answer reusedA service's successful answer from an earlier query, used again because of reuse successes

Answer colours in the view: true, false, text, late (purple), eod (grey), Error (red), and a shaded scale for numbers.