for (v in x) {} should iterate over lazy values, and for (k, v in x) {} should iterate over eager keys and lazy values.
Originally created by @bioball on GitHub (Apr 5, 2024).
```groovy
x = new {
["one"] = 1
["two"] = this["one"] + 1
}
y = (x) {
for (k, v in x) {
[k] = v + 1
}
}
```
Here, `y["two"]` should be 4, not 3.
`for (v in x) {}` should iterate over lazy values, and `for (k, v in x) {}` should iterate over eager keys and lazy values.
adam
added the bug label 2025-12-30 01:21:20 +01:00
In my mind, lazy evaluation of v means that x[k] is only evaluated if and when v is accessed. However, this won't change the resulting value.
What you seem to be arguing for is some kind of macro expansion, i.e., replace every occurrence of v with the definition of x[k] rather than the value of x[k]. Why would this be desirable? At first sight it seems impossible to comprehend.
@odenix commented on GitHub (Dec 7, 2024):
In my mind, lazy evaluation of `v` means that `x[k]` is only evaluated if and when `v` is accessed. However, this won't change the resulting value.
What you seem to be arguing for is some kind of macro expansion, i.e., replace every occurrence of `v` with the definition of `x[k]` rather than the value of `x[k]`. Why would this be desirable? At first sight it seems impossible to comprehend.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @bioball on GitHub (Apr 5, 2024).
Here,
y["two"]should be 4, not 3.for (v in x) {}should iterate over lazy values, andfor (k, v in x) {}should iterate over eager keys and lazy values.@odenix commented on GitHub (Dec 7, 2024):
In my mind, lazy evaluation of
vmeans thatx[k]is only evaluated if and whenvis accessed. However, this won't change the resulting value.What you seem to be arguing for is some kind of macro expansion, i.e., replace every occurrence of
vwith the definition ofx[k]rather than the value ofx[k]. Why would this be desirable? At first sight it seems impossible to comprehend.