[RFC] Array Index-Based Splitting Shorthand
Opened this issue · 3 comments
I think it might be good for simple-lang to copy from Python 2.7+ on array splitting using the index-based shorthand syntax syntax like so:
fage = [ 1, 2, 4 ]
display fage[.0~.1] // [ 1, 2 ]
display fage[.1] // [ 2, 4 ]
The implementation of this is straight forward with operator overloading in the array object. But the syntax dot before a number is invalid I dont know if it advisable to support that from within the compiler to allow float be declarable as
var fl = .0 //which evaluates to 0.0
Or in the case of the array spiting the operator overloading method should accept the argument as string instead such as
fage = [1, 2, 4]
display fage[".1"] // [ 2, 4 ]
The method above can be conflicting if the list is used as a key value pair e.g fage[".1"] = 20
.
I also have less understanding on how this splitting work a link to it documentation will be appreciated.
Or in the case of the array spiting the operator overloading method should accept the argument as string instead such as
Okay, I agree with the string version which you have suggested.
The method above can be conflicting if the list is used as a key value pair e.g fage[".1"] = 20
Can the compiler throw an error if someone tries to use the syntax in this way (i.e. as a setter) ?
I also have less understanding on how this splitting work a link to it documentation will be appreciated.
I will also provide a suitable documentation soon
Can the compiler throw an error if someone tries to use the syntax in this way (i.e. as a setter) ?
No the compiler does not throw an error because it valid.
fage[".1"] = 20
#is simple
fage = [
[".1", 20]
]
Another better option is to use another method to achieve such behavior to prevent conflicting implementations. e.g fage.IndexSplit(".1")