Qu

progress

Builtin index · REPL & diagnostics

progress(i, n)

Input: i, n · Output: no output

What it is

A tqdm-style progress bar, called once per loop iteration: i is the 0-based index (0 through n - 1), n is the total count. Draws [####------] 42% (420/1000) 123.4/s eta 4.7s and redraws in place with a carriage return, throttled to at most once per 100ms (the first and last frame always draw regardless). Resets its own clock whenever i is 0, so a second loop in the same script gets its own rate and ETA. Errors if i is out of 0..n-1 — the common mistake is calling it from for i = 1 to n instead of for i = 0 to n - 1.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
progress(i, n)
i —not documented yet
n —not documented yet
no outputDraws [####------] 42% (420/1000) 123.4/s eta 4.7s and redraws in place with a carriage return, throttled to at most once per 100ms (the first and last frame always draw regardless).

Examples

No documentation example calls this form yet. The REPL & diagnostics chapter is where one belongs.

How it works

progress(i, n) (a tqdm-style progress indicator, Ahmed's own request) — called once per loop iteration, i 0-based and i < n: for i = 0 to n - 1 ... progress(i, n) ... end for is the idiom. Deliberately NOT a for-loop wrapper or new syntax (which would need real interpreter/parser surgery) — a single explicit builtin next to tic/toc does the same job with no new mechanism, and degrades gracefully: a script that never calls it pays nothing. Draws [####------] 42% (420/1000) 123.4/s eta 4.7s and redraws in place via \r -- a real terminal overwrites the line; a captured/report output just carries the \r characters, same trade-off tic/toc and friends already make for being terminal-shaped tools. Resets its own clock whenever i == 0, so a second loop in the same script gets its own rate/ETA rather than inheriting the first loop's elapsed time -- and throttles redraws to at most once per 100ms (always drawing the first and last frame regardless of the clock) so a tight loop over millions of items does not spend more time drawing the bar than doing the work it measures.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.