Qu

append

Builtin index · Collections & strings

result = append(collection, value)

Input: collection, value · Output: result

What it is

collection is a Vec or List; value is the element to add.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = append(collection, value)
collection Vec or Listcollection is a Vec or List.
value —value is the element to add.
result Vec or List
Returns a NEW Vec/List with value added at the end.

Examples

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

acc = ()
for i = 1 to 6
    acc = append(acc, i * i)
end for
print(acc)          # (1, 4, 9, 16, 25, 36)

print(len(acc))     # 6

output
(1, 4, 9, 16, 25, 36)
6

from agent-guide

sizes = [100, 1000, 10000, 100000]
times = []
for n in sizes
    tic()
    total = 0
    for j in 1 to n
        total = total + j
    end
    dt = toc()
    times = append(times, dt)
end
label = estimate_complexity(sizes, times)   # e.g. "O(n)"

print("estimated complexity label = {label}")

from repl-diagnostics

lp = butter(4, "low", 80, 1000)

function lp_block(b, st)
    s   = st
    out = ()
    for v in b
        s   = filter_next(s, v)
        out = append(out, s.y)
    end for
    return (out, s)
end function

p = processor("lp_block", block = 256, state = filter_init(lp), rate = 1000)
y = process(p, x)          # or: p.process(x)


print("{p.latency} samples, {p.latency_ms} ms")   # 256 samples, 256 ms

output
256 samples, 256 ms

from signal-processing

How it works

append(collection, value) — returns a NEW list/vector with value added at the end; the natural companion to insert/remove, same immutable-return convention.

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