Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Array Index-Based Splitting Shorthand #4

Open
isocroft opened this issue Jun 19, 2019 · 3 comments
Open

[RFC] Array Index-Based Splitting Shorthand #4

isocroft opened this issue Jun 19, 2019 · 3 comments

Comments

@isocroft
Copy link

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 ]
@Thecarisma
Copy link
Contributor

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.

@isocroft
Copy link
Author

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

@Thecarisma
Copy link
Contributor

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")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants