Alter Query¶
The alter function modifies elements at specific indices in Vectors, Lists, or Tables using a function. It applies the function to the element at the specified index with a given value.
The alter function takes 3-4 arguments:
- The object to modify (vector, list, or table)
- A binary Function to apply
- An optional index (if omitted, applies to all elements)
- A value to use with the function
Working with Tables¶
When working with Tables, specify the column name as a symbol:
(set trades (table [price volume] (list [100 200] [50 60])))
(set trades (alter trades + 'price 10)) ;; Add 10 to all values in the price column
(select {price: price volume: volume from: trades})
┌───────┬────────┐
│ price │ volume │
├───────┼────────┤
│ 110 │ 50 │
│ 210 │ 60 │
└───────┴────────┘
In-Place Modification¶
To modify the object in place without reassigning, pass the object name as a quoted Symbol: