For generators are eager in values, but should be lazy #130

Open
opened 2025-12-30 01:21:20 +01:00 by adam · 1 comment
Owner

Originally created by @bioball on GitHub (Apr 5, 2024).

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.

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
Author
Owner

@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.

@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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#130