openlang

When a pattern should remember a value

Partly reviewed

A hypothetical Ruby filter has expected = 7 and receives [9]. A reader takes in [expected] to mean “accept only seven”, but the bare variable pattern binds the incoming value. in [^expected] uses the existing value instead. That tiny hat carries quite a bit of meaning.

Which spelling makes the comparison clearer? For a more involved condition, would in [value] if value == expected make the binding and the test easier to follow? I like the compact pin here, but would not hide a complicated condition behind compactness.

The conversation continues 1

Follow the reasoning