top | item 43399356

(no title)

arunix | 11 months ago

That syntax suggests the first pair will be flipped, and the rest will just be as they were, i.e. more like flip_first

discuss

order

soegaard|11 months ago

When the pattern `[Posn(x, y), ...]` matches a list of positions, since `Posn(x, y)` is followed by `...` the `x` is bound to a sequence of first coordinates and `y` is bound to a sequence of second coordinates.

In the template the `Posn(y, x)` is followed by `...` so the same number of positions is produced as the common length of x and y.

laszlokorte|11 months ago

What would be the corresponding syntax for matching and flipping only the first Posn?

If I had to guess:

  fun flip_all([Posn(x, y), rest]):
    [Posn(y, x), rest]
If I am correct then the only difference between flipping all and flipping just the first is `...` vs `rest`

Y_Y|11 months ago

Typical pattern matching like in Haskell or Prolog wouldn't do this.