#No data, and errors
Every answer in eLucid8 is one of three things:
- data: a number, true or false;
- eod (end of data): there is no data at that point;
- an error, which says where it started and why.
There is no silent NaN or empty cell: a gap is eod, a failure is an error.
-- Gaps, a division by zero, and what to do about them.
gappy = restrict if mod(#t, 4) == 3 then eod else #t to (t : 12) end
ratio = 12 / gappy
missing = restrict iseod(gappy) to (t : 12) end
filled = restrict default(gappy, 0) to (t : 12) end
checked = if gappy > 8 then error("too high") else gappy
eod_wins = gappy + 1 / (#t - 3)
-- ask ratio[t = 0]
-- expect gappy[t = 3] = eod
-- expect ratio[t = 4] = 3
-- expect ratio[t = 0] = error division: division by zero
-- expect ratio[t = 3] = eod
-- expect missing[t = 3] = true
-- expect filled[t = 3] = 0
-- expect checked[t = 9] = error raised: too high
-- expect checked[t = 7] = eod
-- expect eod_wins[t = 3] = eod
-- expect eod_wins[t = 4] = 5
How to read it:
gappyis#t, except every fourth point (3, 7, 11), where the program writeseoditself: a gap in the data.ratiodivides 12 by it. Att = 0that is a division by zero: an error. Att = 3it reads eod, so it is eod: operators pass eod and errors on.iseod(gappy)is true wheregappyis eod;default(gappy, 0)isgappy, or 0 where it is eod. (iserroris the same test for errors.)error("too high")makes an error with your own message:checkedrejects readings above 8.- eod wins over an error. At
t = 3,eod_winsadds eod (fromgappy) to a division by zero: the answer is eod. Where there is no data, there is nothing to have gone wrong.
#Try it in the playground
- The answer is there as the program opens, with no button to press:
ratio[t = 0]is an error, division by zero. - In Visualize, look at
ratio's row: eod and the error are drawn apart from the numbers, and from each other. - Press Why? on the error: the trace shows where it started.
- Query
filledand compare its row withgappy's: the gaps are 0.
#Ask your own AI
Using eLucid8's reference at https://elucid8-lang.org/llms.txt, write a Beginner eLucid8 program (equations only: no input or output lines) with ten made-up readings where two are missing (eod), and a value that fills each gap with the reading before it. Compile it with the elucid8 tools before you show it, and give me its Open in playground link.