Substring Assignment

Added November 2018

A rather unique feature of A-Shell BASIC—inherited from A-BASIC—is the ability to use the substring operator on the left side of an assignment in order to update a substring of the destination variable. For example:

a$[x,y] = z$

dst$[-4,-1] = src[-4,-1]

rec[1;5] = "12345"

 

Although this is a very handy feature, unfortunately it is also potentially confusing, for multiple reasons:

•   The substring specifications are based on the physical size of the destination variable, but the logical size of the source variable. 

•   Null bytes in string (but not X) destination variables preceding the start of the target substring will typically be converted to spaces.

•   The preceding rule gets more complicated in the case of dynamic variables (see History below).

The forum article " Question About Substrings" provides some additional explanation.

History

2018 July, A-Shell 6.5.1639:  Language runtime refinement: when an assignment is made to a substring (aka slice) of a dynamic variable, the variable is now expanded as needed for the referenced slice to be part of the variable. For example:

map1 var,x,0

var[9;3] = "foo"

print var[9;3]

 

Previously, the print statement would have printed nothing; the assignment statement would have had no effect, since the variable var was not long enough for the [9;3] slice to be applicable.

Now, it will be expanded, with leading bytes filled with spaces for string type variables or nulls for X type variables, so that the print statement will always display "foo".

This brings the behavior more into line with the expectation for dynamic variables, which are normally expanded as needed during assignment statements. But the slice assignment has always been a very special case.