The ability to overload the "in" operator to allow for the full recreation of a list datum/structure.
List/proc/operatorin()
ID:2472728
Jun 1 2019, 11:03 am
|
|||||||
| |||||||
The ability to overload the "in" operator to allow for the full recreation of a list datum/structure.
List/proc/operatorin()
|
Jun 19 2019, 10:41 pm
|
|
Yes please. If there's an operator it should be overrideable.
|
It would definitely be nice to have in theory, but how would it work in practice? BYOND doesn't have iterators, so what would it return? A list?
EDIT: Oh right, the actual operator use of it Yeah, that one would be pretty easy to figure out It wouldn't be a full recreation without both uses of it though |
We want this:
a in b // "is a in b?" With these, we can make our own lists and use them the same exact way. |
For iteration, this would be even more powerful:
https://docs.microsoft.com/en-us/dotnet/api/ system.collections.ienumerator |
Basically, C#-style iterators are any class with this interface :
iterator They can be iterated one at a time or all at once with the pattern: var/iterator/it = // some iterator There is an example of this in the engine already -- database queries: database/query Clearly, database queries can be used as iterators of row data. In C#, the "foreach()" statement can be used with anything that can provide an iterator over its elements. (C# calls those providers "IEnumerable", I'm calling them "iterable".) // From this: In DM, you can provide an iterator for the built-in /list like so: iterator/from_list So, foreach() in DM would work like this: // From this, which we can already do: And of course this would also apply to database queries (which are their own iterator): var/database/query/q = new("SELECT ...") In C#, functions can be made to return an iterator that iterates values that are "yield returned" in the function itself: IEnumerator Numbers() { "yield return" makes the function wait there until the next value is requested. |