5 ms·
Erlang's statement separators seem to me more like English. I don't hear a lot of complaints about commas, semicolons, and periods in English and I don't find i
by ams6110 8y ago
Erlang's statement separators seem to me more like English. I don't hear a lot of complaints about commas, semicolons, and periods in English and I don't find it an issue in Erlang.
- staticassertion 8y agoPeople fuck up commas and semicolons basically constantly in English.
- segmondy 8y agoI was going to rage on the author, but I'll just let it go. "," means AND. ";" means OR. "." ends the rules. In Algol based languages ";" ends each statement. To apply OR or AND conditions between statements, you then need to use if/then/switch conditions.
- PhantomGremlin 8y agoIn Algol based languages ";" ends each statement. To be pedantic about it, in ALGOL, the original "Algol based language", the semicolon is a separator. There are lots of "missing" semicolons in ALGOL programs. See the examples here: https://en.wikipedia.org/wiki/ALGOL#Code_sample_comparisons https://en.wikipedia.org/wiki/ALGOL#Code_sample_comparisons I think that is more confusing than what C does. E.g. look at the ALGOL 68 example. One 'od' ends with a semicolon, the other doesn't. I dunno if that example is correct or not, I haven't written an ALGOL program in about 45 years.
- tom_mellior 8y agoThis 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.