[erlang-questions] Funargs: Ruby-like blocks for Erlang
Richard O'Keefe
ok@REDACTED
Fri Jul 22 05:10:24 CEST 2011
On 22/07/2011, at 1:01 PM, Tony Arcieri wrote:
> On Thu, Jul 21, 2011 at 5:25 PM, Jachym Holecek <freza@REDACTED> wrote:
> Please define what kind of correspondence you have in mind, and if you're
> going to mention presence of some symbols in Latin alphabet please explain
> why that matters at all.
>
> I mean honestly, are you trolling me?
No, he pretty obviously wasn't.
>
> Tokens like "do" and "end" are words, or more specifically keywords.
And in Algol 60, which pretty much invented the concept,
keywords counted as single characters in the abstract alphabet
and could be freely replaced by other words or even actual characters
in implementations. (This also applied in Algol 68.)
> Tokens like "->" are symbols. Believe it or not for most people groupings of letters, as opposed to symbolic characters, actually has a significant meaning.
OK, so what's the significant meaning of
An bhfuil an fear tromchúiseach?
without looking it up?
>
> To me they're just syntactic items.
>
> Can you think like a human instead of a lexer?
I don't know Jachym Holecek at all, but with that name, I'm guessing
he might be from the Czech Republic. We might all, from time to time,
try thinking like a human being whose native language is not English
and isn't particularly English-like. To such a person, a keyword
like SML's "fn" or Erlang's "bsl" has no more significant meaning
than Haskell's "\" or C's "<<".
>
> Let's have a look:
>
> fun (X) -> X end
> ^^^ ^^^
>
> One more look:
>
> fun (X) -> X; (Y) -> Y end
> ^^^ ^^^
>
> See? Happy now? :-)
>
> No. Clause bodies are delimited by "->" and "end" with ";" as an optional clause separator. The "fun" keyword is not the delimiter and can be used in contexts where a fun has no clause body, such as fun module:function/arity.
This is so wrong an understanding of Erlang syntax that I don't know where to start.
Consider this:
_____________ ______________
fun (true) -> f() ; (false) -> g() end
| |_____ |_____ |
|____________________________________|
The "fun" matches the "end".
NEITHER "->" matches the "end".
Neither "->" has ANY matching token at the right.
If the rightmost "->" matched the "end", what would the leftmost one be doing?
If the leftmost "->" matched the "end", what kind of thing would
(body ; arguments -> body) be?
You need an understanding of Erlang syntax that works with legal Erlang examples.
It's
lambda
: FUN fun_clauses END
| FUN fun_name
;
fun_clauses
: fun_clause
| fun_clauses SEMI fun_clause
;
fun_clause
: fun_head ARROW body
;
fun_head
: arguments WHEN guard
| arguments
;
The fact that "fun" can be used without arguments or body or "end"
can in no way be taken to mean that it is not the delimiter when
there _is_ an end, just as the fact that "-" can be used without
a left operand means that it isn't an infix operator when it
_does_ have a left operand.
In this case, ";" and "->" *look* like and *act* like infix operators.
Neither of them is a bracket, here or anywhere else.
More information about the erlang-questions
mailing list