Probably could use more testing but I thought this might be fun:
' slice test.bas SmallBASIC 0.12.9 (B+=MGA) 2017-05-23
' Attempt of sim of Python's slice, not nearly as elegant
' need 2 forms one for strings and one for single dimension array = list
func sSlice(s, start, finish) 'string Slice
if start <= len(s) then
if start > 0 then
sSlice = iff( finish >= len(s), mid(s, start), mid(s, start, finish - start + 1) )
sSlice = iff( finish >= len(s), mid(s, 1), mid(s, 1, finish) )
sSlice = ""
func aSlice(a, start, finish) 'array (one dimension list)
local ta, i
if start < lbound(a) then start = lbound(a)
if finish > ubound(a) then finish = ubound(a)
for i = start to finish
ta << a(i)
aSlice = ta
test = "123456789"
? "sSlice test = ";sSlice(test,-1, 1);sSlice(test, 2, 4);sSlice(test,5, 15)
Yes, I thought this more powerful than a JB WORD$(s$, wNumber [, delimiter]) Sim for a parser, but JB is base 1 like the my sSlice for a string. So it might be confusing that aSlice is 0 based? Oh well...
im quite happy (sometimes) with oop as an underlying technology. other times its just bloat and overhead for no good reason.
i dont enjoy using anything when it lags, but i tolerate pythons lack of speed-- which most of the time i dont notice, because i dont have much interest in faster things that are less flexible.
but bring oop to the surface and it just gets in my way. i almost never use global variables in my functions, nor do i require instances of those functions with their own variables. nor do i need big globs of variables that are not an array or hash table. im not saying that those are useless things-- very useful for some purposes, but they are not terribly useful to me; more like a distraction. when blatant oop can be easily avoided, it keeps things simpler-- but if you like it, thats fine. its just not my thing.