String functions may not
be nested. What does this mean?
String functions are built using a
string accumulator which is a 256 byte buffer. There is only one string
accumulator due to memory constraints. The general expression evaluation
for integers involves a stack, but it is impractical in the ARMmite to have a string stack. So when a string
is built from an expression, it uses this string accumulator. String FUNCTIONs also use
this string accumulator to return the string value.
So string FUNCTIONs can not be used after the first operand in a string
expression.
String expressions are parsed left to right, and
parenthesis for grouping are not allowed as that is the equivalent of
nesting. However a string expression can have any number of strings being
combined into a single string. So the following is proper-
a$ = a$ + "abcd" + str(2 + 44 / 33) + str(len(a$)) +
"zcxv" + chr(13) + "more stuff" +b$
The chr(13) inserts a carriage return into this string
so it spans 2 lines. This is proper as strings only have two
limitations. First that they are less that 256 bytes, and they are
terminated by a 0 or null character.
Note that the
str(2 + 44 / 33) involves the integer evaluation stack and is OK
as that is a seperate entity. Also the str(len(a$)) is valid as that
involves a string as stored in memory.
What would not be allowed is something like
a$ = "length is " + str(len( c$ +
b$)) ' THIS IS INVALID
NESTING
because c$ + b$ would have to
be evaluated before a$ could be built, and there is no room to do that.
a$ = "length is " + str(len(c$) +
len(b$)) ' allowed as len is called with simple
pointers
User FUNCTIONs
Now with the addition of
user defined functions, there is the possibility of a nested string function that the
compiler can not detect. If a string expression calls a user function, and that
user function does any string expressions or PRINT statements; then this is a
nested string operation. The compiler will not be able to detect this, and
its possible to get unexpected string results or even data abort errors.
a$ = user_string_function
(1,2,3)
' is OK
a$ = str (user_integer_function
(1,2,3)) ' is OK
a$ = "result of " +
user_string_function
(1,2,3)
' INVALID string
nesting
a$ = "result of "+
str(user_integer_function (1,2,3))
' valid only if no string op or PRINT statement in
user_integer_function
a$ = user_string_function (1,2,3) + "
returned" ' is OK,
as the string function was the first called
a$ = str(user_int_function (1,2,3)) + " returned"
' is OK, as the user function
was the first
called