Fixed and dynamic typed arrays
Declare an element type, compare fixed length with doubling capacity, and see find switch from linear to binary search after sorting.
// Both typed array families are built in; no import is required.
let fixed = Array<Int64>(size: 4, fill: 0)
fixed[0] = 30
fixed[1] = 10
fixed[2] = 20
print(fixed.to_list())
fixed.sort()
print(fixed.to_list())
print(fixed.find(20))
let values = DynamicArray<Int64>(capacity: 2)
values.append(30)
values.append(10)
values.append(20) // Capacity doubles from 2 to 4.
print(values.len())
print(values.capacity())
print(values.is_sorted())
print(values.find(20))
values.sort()
print(values.is_sorted())
print(values.find(20))
values[0] = 99 // Sorted metadata is maintained after every mutation.
print(values.is_sorted())
print(values.find(20))
let independent = values.copy()
values[0] = 5
print(independent.to_list())
let words = DynamicArray<String>(capacity: 2)
words.append("pear")
words.append("apple")
words.sort()
print(words.to_list())
Make it your experiment.
Use Aner 0.0.3 or newer. Save this program as examples/arrays_basic.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.
aner check examples/arrays_basic.aner
aner run examples/arrays_basic.anerThe aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.
Use Aner 0.0.3 or newer and matching VS Code integration. Arrays are built in and require no import. Every array requires an explicit fixed width integer, Float32, Float64, Decimal, Bool, or String element type. Decimal uses its own exact arithmetic contract. See the typed array guide for method contracts and complexity. The revised source requires Aner 0.0.4 or newer; earlier executables may reject the syntax.
Bundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.
Dataset sources & attribution