Plain GROUP! & Branching: Only Run If Branch Taken?

Looking at examples in practice, I don't know I'm as convinced it's "good" as I thought:

y: case [
    1 > 2 [<no>]
    1 < 2 [<yes>]
] then x -> [
    assert [x = <yes>]
    1000 + 20
]
assert [y = 10]

vs.

y: case [
    1 > 2 [<no>]
    1 < 2 [<yes>]
] then (x -> [
    assert [x = <yes>]
    1000 + 20
])
assert [y = 10]

When you're used to thinking of branches taking their arguments literally, it's "spooky" to reason about it. What's happening, what order does this run in, etc.

It's hard enough to grasp that a GROUP! is literal and not evaluated unless the branch is taken... but that's reasonable. e.g. people would intuitively say:

"y'know it's probably better if the code for creating the branch doesn't evaluate unless it's going to be taken, so I hope that's what it does."

But what would the intuition say about running that ARROW function? There's no real intuition at work, you have to learn weird rules, reaction would probably be:

"oh. huh. it resolved a literalism fight by letting the right hand side win, because of... some flag somewhere? and it generates a function even if the branch isn't taken? but you optimized that weirdly so it's not as bad as it would be? :face_with_diagonal_mouth: weird."

Think I'm decided now. You need the group.

1 Like