Hmm, "related to", maybe, but I don't really see how one follows from the other. Python arrays/lists are zero-index-based just like BBC BASIC arrays are, but never in BBC BASIC does one specify an index that is one greater than the end of a range, as Python slicing does.DDRM wrote: ↑Tue 19 Dec 2023, 10:02 I suspect it's related to the decision made for "range", and is all consistent with using 0-based numbering. If you write something likeIt will execute the block 10 times - but x will run from 0 to 9.Code: Select all
for x in range(10): <Block>
In my experience there are two common ways of representing a range: first and last or first and count. So for example if one has a list of numbers [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] the two ways of representing the subset [4, 5, 6] would be either (in a BBC BASIC-like syntax) 4 TO 6 or 4 BY 3. Python's 4:7 is an outlier.
I referred to that earlier in the thread. I could support it with 'copied' (read-only) slices but not with 'true' (read-write) slices.Range has more sophisticated forms to run between two integers, with an integer step
As a putative BBC BASIC listlib ought to use a BBC BASIC-like syntax as far as possible, I propose that the range be specified as first and count (which is different from, but not inconsistent with, the Python usage) so my earlier example would become:
Code: Select all
DIM parent(9)
parent() = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
PROC_listslice(parent(), child(), 3, 3)
child() = 11, 12, 13