In many languages strings are handled exactly like arrays. In TScript there are some asymmetries between arrays and strings:
- Strings are not iterable in for loops. Each character should be iterated.
- Strings are concatenated with
+, arrays with concat, (compare Python, Java, etc. which use + for both). Later dialects of BASIC, that allowed string concatenation, also provided the & operator in addition to the + operator. It might be a good idea for beginners to differenciate string concatenation from addition, by introducing the & operator for string and sequence concatenation.
- Arrays have no function for finding elements/sequences in them. There could be a function
array.find(subArray), that works exactly like the find function on strings. When you want to search for a single element, you would simply call array.find([element]) (Square brackets denote the creation of an array here). It might be appropriate to use different function names like array.findSequence(subArray) and array.findElement(element) to disambiguate the function name.
- Strings and ranges have no
keys() and no values() function
As long as some these asymmetries exist, you can use a string like an array, by simply converting it to an array. This would be done with var chars = string.split("");. So to iterate through a string, the following could be used:
# instead of
# for var char in string do ...
# you can currently only use:
for var char in string.split("") do ...
# or
for var i in 0:string.size() do
{
var char = string[i];
...
}
But this might be unintuitive for beginners.
In many languages strings are handled exactly like arrays. In TScript there are some asymmetries between arrays and strings:
+, arrays withconcat, (compare Python, Java, etc. which use+for both). Later dialects of BASIC, that allowed string concatenation, also provided the&operator in addition to the+operator. It might be a good idea for beginners to differenciate string concatenation from addition, by introducing the&operator for string and sequence concatenation.array.find(subArray), that works exactly like thefindfunction on strings. When you want to search for a single element, you would simply callarray.find([element])(Square brackets denote the creation of an array here). It might be appropriate to use different function names likearray.findSequence(subArray)andarray.findElement(element)to disambiguate the function name.keys()and novalues()functionAs long as some these asymmetries exist, you can use a string like an array, by simply converting it to an array. This would be done with
var chars = string.split("");. So to iterate through a string, the following could be used:But this might be unintuitive for beginners.