3 ms·
This could still be simpler without losing anything: It's kind of redundant to use ";" at the end of rules that are followed by another rule for the same functi
by tom_mellior 8y ago
This could still be simpler without losing anything: It's kind of redundant to use ";" at the end of rules that are followed by another rule for the same function. Erlang could just use "." here as well. The parser could still tell that another rule for the same function follows by seeing if another rule for the same function follows ;-)
(Prolog, which influenced this part of Erlang syntax an many others, does it this simpler way. It still sucks if you want to comment out the last line of a clause, or switch the last line of a clause with some other line.)
- triska 8y agoIn Prolog, there is a neat technique that lets you "comment out" any goal of a clause, including the last one, in a completely uniform way. The trick is to define * as a prefix operator, and then define the predicate ( * )/1 to generalize away its argument. You only need two lines to do it: :- op(920,fy, *). *_. Now, you can put * in front of any goal to "remove" it. For example: pred :- true, * false. With this definition, ?- pred. succeeds. In Erlang, you cannot easily replicate this. You can try parse transformations to rewrite code at compilation time: http://erlang.org/doc/man/compile.html http://erlang.org/doc/man/compile.html In Elixir, defining otherwise unused operators is generally discouraged: https://hexdocs.pm/elixir/master/operators.html https://hexdocs.pm/elixir/master/operators.html For exchanging lines, an editor macro may be useful for Erlang and also for Prolog.
- Jtsummers 8y agoSemicolon also appears in other places in erlang (like guards) where it similarly means “choice”. It’s a consistent use of the symbol throughout.