Closed staycoolcall911 closed 1 year ago
@yoav-steinberg: Partial support exists. Still missing many elements:
in
format.The for
statement example is weird
2.7 for statement
the wing code looks like it will print from 0 to 100 (or 99)
for item in 0..100 {
print(item);
}
but the Typescript equivalent print from 99 to 0
// calling 0..100 does not allocate, just returns an iterator
function* iterator(lim) { let i = lim; while (i--) yield i; }
const iter = iterator(100);
for (const val of iter) {
console.log(val);
}
I think it would be better if
for item in 0..100
iterates from 0 to 99
function* iterator(start, end) {
let i = start;
while (i < end) yield i++;
while (i > end) yield--;
}
const iter = iterator(100, 0);
for (const val of iter) {
console.log(val);
}
and for item in 100..0
iterates from 100 to 1
function* iterator(start, end) {
let i = start;
while (i < end) yield i++;
while (i > end) yield i--;
}
const iter = iterator(0, 100);
for (const val of iter) {
console.log(val);
}
@marciocadev Good catch, this looks to me like a bug in the spec. 🙂 Your proposal makes sense. would you like to submit a fix?
@MarkMcCulloh added type checking for iterable in #1412, still left to support the non in
format of for loops.
Wow, iterator works now? Amazing
Congrats! :rocket: This was released in Wing 0.8.35.
https://github.com/winglang/wing/blob/main/docs/04-reference/winglang-spec.md#27-for
@yoav-steinberg: Partial support exists. Still missing many elements:
in
format.