-
Notifications
You must be signed in to change notification settings - Fork 333
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
Allow foreach on 0-indexed arrays #2811
Conversation
I don't think this should be encouraged / supported. As you said it's a small minority of functions It's not a big perf hit like supporting non sequential arrays since this would only be run once, but that isn't really the issue here anyway. |
I'd recommend creating RFC discussions prior to making a PR to make any not objectively better changes |
It seemed objectively better in my sight which is why I didn't, actually. If functions can return 0-indexed arrays, why can't foreach support that? especially since the work required to do so is so small. Either way, the PR is small. I probably won't lose sleep if it's denied. |
High speed components use 0 index so it makes sense to be supported. |
What does this have to do with arrays, though |
Wiremod has (or had) an odd propensity to start arrays at 0, so it should be at least anticipated for. |
This has nothing to do with the E2 data type "array" though. And wiremod outside of E2 hardly ever returns or takes arrays. My philosophy is to keep E2 isolated as much as possible from the rest of wiremod. Trying to make E2 behave like the rest of wiremod and not like a programming language is what got E2 into runOn* and three unary operators for wiremod specific behavior ( |
I guess if you have an array of data you want to write to a high speed component, although I think there are writearray methods or something already for that. Not really sure of other uses so it does seem niche. |
Anything in gmod that returns arrays starting at zero is implemented wrong. Lua is a 1-indexed language and trying to force it not to be is a completely unecessary mistake. As far as I know there's no such function in wiremod and never has been... with the possible exception being a very small amount of functions that just return the output of a gmod function without changing anything. There are a few functions in gmod itself that do return arrays starting at zero but like I said I definitely consider those to be implemented wrong. |
Well, I concede. I'll look into seeing if 0-indexed array returns in E2 can (or should) be converted to 1-indexed. |
A small minority of E2 functions return 0-indexed arrays. This allows one to
foreach
over those arrays, which is at least a convenience improvement over a for loop.Modifies iter operator to return
-1
as its third argument if an array has an element at 0.Test code