Qu

peek

Builtin index · Collections & strings

result = push(q, x) / pop(q) / peek(q)

Input: q, x · Output: result

What it is

On a fifo handle q: push(q, x) adds x at the back (returns Nothing); pop(q) removes and returns the front element; peek(q) looks at it without removing. pop on an empty FIFO is an error. On a queue() โ€” the job queue โ€” push(q, "fname") enqueues a function you defined instead (a Str naming it, not a value).

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = push(q, x) / pop(q) / peek(q)
q —peek(q) looks at it without removing.
x —On a fifo handle q: push(q, x) adds x at the back (returns Nothing).
result —
Returns the front element itself from pop/peek, whatever type was pushed; push hands back no value.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

f = fifo(3)
f.push(1)
f.push(2)
f.push(3)
f.push(4)          # evicts 1 -- buffer is now [2, 3, 4]

print(peek(f))       # 2 -- oldest element, still there

print(f.pop())      # 2

print(len(f))        # 2

output
2
2
2

from collections-strings

How it works

fifo(capacity) (ยง data structures pass, 2026-09-01, Value::Fifo is a guarded arm further up this match (see its own comment there, next to queue()'s own unconditional "push"); every other fifo name has no competing meaning anywhere else, so this arm is unconditional.

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

See also

push, pop — documented in the same entry.