Re: [Erlang Forums] [Erlang/OTP Proposals/Proposals: RFC] Re-visiting EEP-0055

Fred Dushin <[email protected]> Wed, 27 Apr 2022 09:14:05 -0400
Newsgroups gmane.comp.lang.erlang.general
Message-ID <[email protected]>
--Apple-Mail=_A209A61C-EDFE-4630-A7E0-541B4A04952E
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii

So I am a little confused.  Reading the EEP,

f(X, Y) ->
    case X of
        {a, Y} -> ok;
        _ -> error
    end.

means the same as

f(X, Y) ->
    case X of
        {a, ^Y} -> ok;
        _ -> error
    end.

So it adds nothing semantically to the language.

The more compelling example is binding a clause head in a local function =
definition to a previously bound variable.  =46rom the EEP:

f(X, Y) ->
    F =3D fun ({a, ^Y})  -> {ok, Y};
            (_) -> error
        end,
    F(X).

But as noted later in the EEP, this can be written as

f(X, Y) ->
    F =3D fun ({a, Z}) when Z =3D:=3D Y  -> {ok, Y};
            (_) -> error
        end,
    F(X).

So as far as I can see, the proposal is at best proposing syntactic =
sugar over what can already be accomplished in the language.  Current =
Erlang might be more verbose (by character count), but to say it is more =
or less clear is in the eye of the beholder, certainly.

I think the real question is whether the language should admit two ways =
of accomplishing the same thing (and by that, I mean compiling to =
effectively the same BEAM ASM), and that is really up to the language =
maintainers.

If you want my personal opinion (I know, you didn't ask), I lean on the =
side of "Less is more", when it comes to language features.  Having to =
read Scala in my day job, I can't think of a programming language that =
more violates the principle of linguistic parsimony -- it even puts C++ =
to the test!

And not to be too critical, but I am having a hard time understanding =
parts of the Rationale section.  The author(s) suggest(s) that in =
current Erlang temporary variables are needed to achieve the same as the =
proposed glyph, but then provide an example that uses a guard (as above) =
but doesn't use a temporary variable, after all (?)

I am not sure what the problem is with temporary variables.  The =
compiler has registers at its disposal, so I don't think it's a =
performance argument, but more an issue of readability, which again, I =
think is a purely aesthetic question, and has no bearing on the features =
of the language, per se.  In other words, the proposal is not suggesting =
anything that cannot already be achieved in current Erlang, with =
effectively the same compiled BEAM ASM.


Also, kind of a stupid question, but wouldn't

f(X, Y) ->
    case X of
        {a, Y} -> ok;
        _ -> error
    end.

be more clearly written:

f({a, Y}, Y) -> ok;
f(_, _) -> error.

I would never write the former, if I had the option to write the latter, =
but that just may be my personal preference.

-Fred

> On Apr 21, 2022, at 8:32 AM, Leonard Boyce =
<[email protected]> wrote:
>=20
>>=20
>> EEP-0055 (https://github.com/erlang/eep/blob/master/eeps/eep-0055.md) =
was submitted on
>> 21-Dec-2020.


--Apple-Mail=_A209A61C-EDFE-4630-A7E0-541B4A04952E
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=us-ascii

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; =
charset=3Dus-ascii"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; line-break: after-white-space;" class=3D""><div =
class=3D"">So I am a little confused. &nbsp;Reading the EEP,</div><div =
class=3D""><br class=3D""></div><blockquote style=3D"margin: 0 0 0 40px; =
border: none; padding: 0px;" class=3D""><div class=3D""><span =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Monaco;" class=3D"">f(X, Y) -&gt;</span></div><div class=3D""><span =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Monaco;" class=3D"">&nbsp; &nbsp; case X of</span></div><div =
class=3D""><span style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, =
0); font-family: Monaco;" class=3D"">&nbsp; &nbsp; &nbsp; &nbsp; {a, Y} =
-&gt; ok;</span></div><div class=3D""><span style=3D"caret-color: rgb(0, =
0, 0); color: rgb(0, 0, 0); font-family: Monaco;" class=3D"">&nbsp; =
&nbsp; &nbsp; &nbsp; _ -&gt; error</span></div><div class=3D""><span =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Monaco;" class=3D"">&nbsp; &nbsp; end.</span></div></blockquote><div =
class=3D""><br class=3D""></div><div class=3D"">means the same =
as</div><div class=3D""><br class=3D""></div><blockquote style=3D"margin: =
0 0 0 40px; border: none; padding: 0px;" class=3D""><div class=3D""><span =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Monaco;" class=3D"">f(X, Y) -&gt;</span></div><div class=3D""><span =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Monaco;" class=3D"">&nbsp; &nbsp; case X of</span></div><div =
class=3D""><span style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, =
0); font-family: Monaco;" class=3D"">&nbsp; &nbsp; &nbsp; &nbsp; {a, ^Y} =
-&gt; ok;</span></div><div class=3D""><span style=3D"caret-color: rgb(0, =
0, 0); color: rgb(0, 0, 0); font-family: Monaco;" class=3D"">&nbsp; =
&nbsp; &nbsp; &nbsp; _ -&gt; error</span></div><div class=3D""><span =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Monaco;" class=3D"">&nbsp; &nbsp; end.</span></div></blockquote><div =
class=3D""><br class=3D""></div><div class=3D"">So it adds nothing =
semantically to the language.</div><div class=3D""><br =
class=3D""></div><div class=3D"">The more compelling example is binding =
a clause head in a local function definition to a previously bound =
variable. &nbsp;=46rom the EEP:</div><div class=3D""><br =
class=3D""></div><blockquote style=3D"margin: 0 0 0 40px; border: none; =
padding: 0px;" class=3D""><div class=3D""><div class=3D""><font =
face=3D"Monaco" class=3D""><span style=3D"font-style: normal;" =
class=3D"">f(X, Y) -&gt;</span></font></div></div><div class=3D""><div =
class=3D""><font face=3D"Monaco" class=3D""><span style=3D"font-style: =
normal;" class=3D"">&nbsp; &nbsp; F =3D fun ({a, ^Y}) &nbsp;-&gt; {ok, =
Y};</span></font></div></div><div class=3D""><div class=3D""><font =
face=3D"Monaco" class=3D""><span style=3D"font-style: normal;" =
class=3D"">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (_) -&gt; =
error</span></font></div></div><div class=3D""><div class=3D""><font =
face=3D"Monaco" class=3D""><span style=3D"font-style: normal;" =
class=3D"">&nbsp; &nbsp; &nbsp; &nbsp; =
end,</span></font></div></div><div class=3D""><div class=3D""><font =
face=3D"Monaco" class=3D""><span style=3D"font-style: normal;" =
class=3D"">&nbsp; &nbsp; =
F(X).</span></font></div></div></blockquote><div class=3D""><br =
class=3D""></div><div class=3D"">But as noted later in the EEP, this can =
be written as</div><div class=3D""><br class=3D""></div><div =
class=3D""><blockquote style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, =
0, 0); margin: 0px 0px 0px 40px; border: none; padding: 0px;" =
class=3D""><div class=3D""><font face=3D"Monaco" class=3D"">f(X, Y) =
-&gt;</font></div><div class=3D""><font face=3D"Monaco" class=3D"">&nbsp; =
&nbsp; F =3D fun ({a, Z}) when Z =3D:=3D Y &nbsp;-&gt; {ok, =
Y};</font></div><div class=3D""><font face=3D"Monaco" class=3D"">&nbsp; =
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (_) -&gt; error</font></div><div =
class=3D""><font face=3D"Monaco" class=3D"">&nbsp; &nbsp; &nbsp; &nbsp; =
end,</font></div><div class=3D""><font face=3D"Monaco" class=3D"">&nbsp; =
&nbsp; F(X).</font></div></blockquote></div><div class=3D""><br =
class=3D""></div><div class=3D"">So as far as I can see, the proposal is =
at best proposing syntactic sugar over what can already be accomplished =
in the language. &nbsp;Current Erlang might be more verbose (by =
character count), but to say it is more or less clear is in the eye of =
the beholder, certainly.</div><div class=3D""><br class=3D""></div><div =
class=3D"">I think the real question is whether the language should =
admit two ways of accomplishing the same thing (and by that, I mean =
compiling to effectively the same BEAM ASM), and that is really up to =
the language maintainers.</div><div class=3D""><br class=3D""></div><div =
class=3D"">If you want my personal opinion (I know, you didn't ask), I =
lean on the side of "Less is more", when it comes to language features. =
&nbsp;Having to read Scala in my day job, I can't think of a programming =
language that more violates the principle of linguistic parsimony -- it =
even puts C++ to the test!</div><div class=3D""><br class=3D""></div><div =
class=3D"">And not to be too critical, but I am having a hard time =
understanding parts of the Rationale section. &nbsp;The author(s) =
suggest(s) that in current Erlang temporary variables are needed to =
achieve the same as the proposed glyph, but then provide an example that =
uses a guard (as above) but doesn't use a temporary variable, after all =
(?)</div><div class=3D""><br class=3D""></div><div class=3D"">I am not =
sure what the problem is with temporary variables. &nbsp;The compiler =
has registers at its disposal, so I don't think it's a performance =
argument, but more an issue of readability, which again, I think is a =
purely aesthetic question, and has no bearing on the features of the =
language, per se. &nbsp;In other words, the proposal is not suggesting =
anything that cannot already be achieved in current Erlang, <i =
class=3D"">with effectively the same compiled BEAM ASM.</i></div><div =
class=3D""><br class=3D""></div><div class=3D""><br class=3D""></div>Also,=
 kind of a stupid question, but wouldn't<div class=3D""><br =
class=3D""></div><div class=3D""><font face=3D"Monaco" class=3D""><span =
style=3D"font-style: normal;" class=3D"">f(X, Y) -&gt;<br =
class=3D"">&nbsp; &nbsp; case X of<br class=3D"">&nbsp; &nbsp; &nbsp; =
&nbsp; {a, Y} -&gt; ok;<br class=3D"">&nbsp; &nbsp; &nbsp; &nbsp; _ =
-&gt; error<br class=3D"">&nbsp; &nbsp; end.</span></font></div><div =
class=3D""><br class=3D""><div class=3D""><div class=3D"">be more =
clearly written:</div><div class=3D""><br class=3D""></div><span =
style=3D"font-style: normal;" class=3D""><font face=3D"Monaco" =
class=3D"">f({a, Y}, Y) -&gt; ok;<br class=3D"">f(_, _) -&gt; =
error.</font></span></div><div class=3D""><span class=3D""><br =
class=3D""></span><div>I would never write the former, if I had the =
option to write the latter, but that just may be my personal =
preference.</div><div><br class=3D""></div><div>-Fred</div><div><br =
class=3D""><blockquote type=3D"cite" class=3D""><div class=3D"">On Apr =
21, 2022, at 8:32 AM, Leonard Boyce &lt;<a =
href=3D"mailto:[email protected]" =
class=3D"">[email protected]</a>&gt; wrote:</div><br =
class=3D"Apple-interchange-newline"><div class=3D""><div =
class=3D""><blockquote type=3D"cite" class=3D""><br class=3D"">EEP-0055 =
(<a href=3D"https://github.com/erlang/eep/blob/master/eeps/eep-0055.md" =
class=3D"">https://github.com/erlang/eep/blob/master/eeps/eep-0055.md</a>)=
 was submitted on<br class=3D"">21-Dec-2020.<br =
class=3D""></blockquote></div></div></blockquote></div><br =
class=3D""></div></div></body></html>=

--Apple-Mail=_A209A61C-EDFE-4630-A7E0-541B4A04952E--