Generates an element or a slice of elements from a vector, or a character or a piece of the text from a scalar holding text.
Vector fields and scalar fields holding text.
For a vector defined as <v:vector {A}, {B}, {C}, {D}, {E}, {F}, {G}>:
<v.@ 1> generates the first element, {A}.<v.@ 2,5> generates the 2nd to the 5th elements inclusive. They're all text, so they join into one piece of text: {BCDE}.<v.@ -3,-1> generates the 3rd-last to the last elements: {EFG}.<v.@ 2,-1,2> generates every second element from the 2nd to the last: {BDF}.<v.@ -1,1,-1> generates the elements in reverse order: {GFEDCBA}.For a vector defined as <n:vector 10, 20, 30, 40>:
<n.@ 2,3> generates two values, 20, 30.For a scalar defined as <s:scalar {Hello World!}>:
<s.@ 1> generates the first character, {H}.<s.@ 1,5> generates the 1st to the 5th characters: {Hello}.<s.@ -6,-1> generates the last six characters: {World!}.<s.@ -1,1,-1> generates the text reversed: {!dlroW olleH}.Takes one, two or three numbers:
<v.@ 5,2> generates {EDCB}.2 takes every second position, and a negative step runs backwards. A step that would go past the end of the range stops at the last position before it: <v.@ 1,6,2> generates {ACE}.<v.@ 3,3> generates {C}.Positions start at 1. Negative positions count back from the end, so -1 is the last.
On a vector, the operator generates the chosen elements, in order. Text that ends up next to other text joins into one piece of text, just as it does anywhere else, so a slice of text elements generates a single piece of text. Values that aren't text stay separate: for <m:vector {a}, {b}, 1, {c}, {d}>, <m.@ 1,5> generates three values, {ab}, 1, {cd}. To get text elements as separate values, pick each one: <x:vector <v.@ 2>, <v.@ 3>> holds two elements.
On a scalar holding text, the operator works on the characters of the text, and generates a piece of the text. A scalar holding a number isn't text: it counts as a single value, so only <k.@ 1> works on it. To pick out digits, store the number as text, as in <k:scalar {12345}>.
Naming the result creates a scalar for a single position and a vector for a range: <x:v.@ 2,4> creates a vector holding one element, {BCD}.
A position that doesn't exist generates invalid, and the console reports "index out of range" in the terminal (or "slice out of range" for a range). Position 0 doesn't exist.
A step of 0, or a step that runs the opposite way to the range, can never reach the end of the range, so it also generates invalid and reports "slice out of range": <v.@ 2,5,-1> and <v.@ 2,5,0> are both invalid.
The operator takes values, so it needs angle brackets of its own: <putLn <v.@ 2>>. Without them, the values would be read as part of the surrounding tag.