Is there a way to write a string that ends with a backslash? The way `slurp_one_past_backslashes` is used seems to make that impossible.
EDIT: I thought typing a literal 0 byte might work, but apparently mu uses a different mechanism to delimit strings in memory.
x:address:array:char <- new [abc]
would look like this in memory, assuming the allocator returned address 1000 as the value of x: 1000: 3
1001: 97 # a
1002: 98 # b
1003: 99 # c
That's it. There's no trailing null character. Address 1004 is not part of this allocation.The length of the array cannot be modified, only read (using instruction length). If we need a larger array we must allocate new and copy over, just like in C.
The elements of an array can be read and written using instructions index and put-index, respectively. Here's a fragment of code to make the final character of x a backslash:
len:num <- length *x
last:num <- subtract len, 1
put-index *x, last, 92 # ascii code for backslash
[1] The verbose "address:array:char" (read as "address to an array of characters") is typically abbreviated as "text" in Mu programs. I've written out the full type to make things more explicit.If you want to construct it from scratch, strings and arrays in general are prefixed with their length. put-index on the final index would be the workaround.
How do you write the string with characters '\' and ']'? It seems like the natural way to write it, [\\\]], would end up being lexed as [\\\] (a string with two backslashes) followed by an unmatched string end character ']'.