Extra syntactic constructs are provided to access and modify characters in strings:
expr: ... | expr.[
expr]
| expr.[
expr]
<-
expr
The expression expr1 .[
expr2 ]
is equivalent to the
application nth_char
expr1 expr2. In the initial environment,
the identifier nth_char
resolves to a built-in function that
returns the character number expr2 in the string denoted by
expr1. The first element has number 0; the last element has number
n-1, where n is the length of the string. The exception
Invalid_argument is raised if the access is out of bounds.
The expression expr1 .[
expr2 ]
<-
expr3 is equivalent to
set_nth_char
expr1 expr2 expr3. In the initial environment,
the identifier set_nth_char
resolves to a built-in function that
modifies in-place the string denoted by expr1, replacing character
number expr2 by the value of expr3. The exception
Invalid_argument is raised if the access is out of bounds. The
built-in function returns ()
.