append builtin
The append builtin appends one or more elements to a slice (array) and returns the resulting slice. It mirrors Go-like behavior.
- Name:
append - Signature:
append(slice, elems...) -> slice - Variadic: yes
- Type safety:
- Untyped arrays allow mixed element types (existing language behavior)
- Typed arrays enforce that appended element types match the element type
- Returns: a new slice value containing original elements plus appended elements
Examples
| Append Examples | |
|---|---|
Notes: - The returned slice may or may not share storage with the original (implementation detail). Treat the result as the new slice. - For typed arrays, appending an incompatible type is a compile-time error (when possible) and a runtime error otherwise.