[erlang-questions] Funargs: Ruby-like blocks for Erlang

Jachym Holecek freza@REDACTED
Fri Jul 22 04:28:35 CEST 2011

# Tony Arcieri 2011-07-22:
> 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 -- there was an attempt at humor later on, but overall I'm serious.

> Tokens like "do" and "end" are words, or more specifically keywords. Tokens like "->" are symbols.
> Believe it or not for most people groupings of letters, as opposed to symbolic characters, actually
> has a significant meaning.

Are you sure you'd convince a Chinese programmer with little to no English skills
here? I remember that when I was starting programming the language had an UNLESS
statement (some dialect of BASIC I think, too tired to be sure ATM) -- didn't know
what that word meant, but that hardly stopped me... Sure, it was nice that it was
in Latin alphabet instead of Greek or something, but it (= it's word-y nature)
wasn't terribly significant either.

>     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.

Wait. This was in response to:

  The "end" keyword, in all other cases in Erlang, is paired with a corresponding keyword, like "if",
  or "case", or "receive", or "try". Only in funs is "end" paired with the stabby symbol. If anything
  Erlang's fun syntax is inconsistent.

Which is wrong like I say, to quote lib/stdlib/src/erl_parse.yrl:

  fun_expr -> 'fun' fun_clauses 'end' : build_fun(?line('$1'), '$2').

  fun_clauses -> fun_clause : ['$1'].
  fun_clauses -> fun_clause ';' fun_clauses : ['$1' | '$3'].

The "fun M:F/A" is an atomic thing, no need for pairing there as there's no
expression to enclose. And "->" has nothing to do with ";" -- the former
separates pattern from clause body, the latter separates clauses from one

If you're really talking just about the aesthetical aspects of code seen as
sequence of characters (regardless of the abstract structure it encodes) than
well, you're surely free to, I just don't see the point -- and actually it's
possibly counterproductive too: it's this clear underlying structure that
(when done right) makes code feel intuitive and easy to work with.

For example, in your proposal, can I pattern-match on arguments? Use guards?
If so, will they look the same they usually look? Can I do multi-clause "do"s?
How comes you're depriving functions of bits of their arity (this kind of
implicit trickery doesn't happen anywhere else in Erlang)? Is this proposal
limited to cases that have a Fun as first argument? That again is a new
thing in the language.

So: why replace perceived inconsistency in the language by actual hardcore
one (seems that way so far)? More importantly: aren't there more significant
aspects of the language to focus on instead of something that's already
handled pretty well? (Sure, your call, just saying)

	-- Jachym

More information about the erlang-questions mailing list