alpaca icon indicating copy to clipboard operation
alpaca copied to clipboard

Reuse variable in pattern matches for equality

Open j14159 opened this issue 7 years ago • 2 comments

In Erlang we can do the following to express two tuple items that are equal:

case Tuple of
    {X, X} -> ...
end

In Alpaca we currently have to do this:

match tuple with
  (x, y), x == y -> ...

I'd much prefer for us to be able to be like Erlang here:

match tuple with
  (x, x) -> ...

The latter seems like a more expressive form to me. This should be relatively simple to solve in the AST generation stage by rewriting multiple occurrences of a symbol in a pattern to a sequence of synthesized names and some added equality guards.

j14159 avatar Jan 01 '17 00:01 j14159

@rvirding, can you chime in here re: why LFE does it the same way as Alpaca currently does?

yurrriq avatar Jan 06 '17 21:01 yurrriq

Just felt that the implicit equality testing felt more logic than functional. It also mapped more directly onto core erlang :-). I am not that fixed on it.

rvirding avatar Jan 06 '17 22:01 rvirding