Slicing, not as modern as you thought

Era Scarecrow rtcvb32 at yahoo.com
Mon Jul 8 04:39:10 UTC 2019


On Sunday, 7 July 2019 at 14:12:05 UTC, Patrick Schluter wrote:
> the lowly Sinclair ZX81 already implemented slicing in its 
> Basic string handling.

  So present in BASIC which Microsoft did.

  Keep in mind all 6502's had super limited memory, an 8bit chip, 
8bit address space & registers with *SOME* 16 bit addressing 
options (including using the 0-page, or addresses hard coded).

  So with super limited space and no real memory management (you 
can sorta allocate space but never free it); That and strings 99% 
of the time were being replaced (or printed) and not modified in 
place, it's easy enough to reason they'd rather point to the same 
address (and not slow it down with duplicating data or have to 
deal with running out of precious 20k of ram). Arrays in BASIC 
were as you said, have an offset an a size. But there's no real 
dup option or the like, or splitting appending or doing 
interesting and fun things with the GC.

  Interesting to bring up. Honestly tinkering with Burrow Wheeling 
Transformation, i did something similar, doing a single short 
array to slice and make a huge number of arrays, but keeping 
allocation to a minimum (more for performance reasons and not for 
minimal memory usage).

  Also, you could have easily done the same thing in C anyways, as 
it's all just pointers and ints anyways, nothing would be 
stopping you from pointing to the middle of a string and then 
just saying it's N length (unless you absolutely required the \0 
terminating byte).


More information about the Digitalmars-d mailing list