int
Theint filter takes a single argument, a string filter. If the string represented by that filter consists of a nonempty sequence of digits, optionally preceded
by a minus sign, then the value of the filter is the integer represented by string. Otherwise, the int filter fails to match.
int "32" ≡ 32
int "-2" ≡ -2
int "xy" // fails to match
The int filter has lower precedence than +:
int "32" + "1" ≡ 321 // string concatenation, same as
int ("32" + "1")
int "32" + 1 ≡ 33 //arithemic addition, same as
(int "32") + 1
examples
Theint filter is mainly used with regular expressions to convert sequences of digits to integers. For example, suppose some comments contains strings like "Eval: 24" in them.
We can convert these to integers:
Eval = {comment ~~ "Eval: (\d+)"
int \1}