Erlang improvement?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Erlang improvement?

Kostis Sagonas-3
Dear Erlang users,

The HiPE group, besides developing a faster implementation of Erlang,
is also aiming at cleaning up the language from some (occasionally
unfortunate) constructs which were once upon a time added to the
language (perhaps for a good reason) but are arguably not so useful
anymore, ugly, or add unnecessary overhead to some operations.

Today, we stumbled upon one of these "remains of the past", and
decided that it is probably not worth our while to support this, in
our opinion weird, construct in HiPE.  We instead think that it is
probably a better idea to discontinue its support from future
releases of Erlang/OTP.

We would like to use this forum to conduct a poll on whether Erlang
users really use this "feature" and whether there are applications out
there that depend on this.  So, if you do have an application that
uses this construct, please do speak up at this point.


In Erlang, it is currently possible to write the following:

%%===============================================================
-module(erlang_is_a_fun_language).
-export([test/0,f/2]).

test() ->
  t2(?MODULE,f).

t2(M,F) ->
  {M,F}(bar,42).   %% WEIRD SYNTAX FOR "funs"

f(_,_) ->
  ok.
%%===============================================================

Instead, we think that the following syntax is a much better way to
write the above:

%%===============================================================

t2(M,F) ->
  M:F(bar,42).

%%===============================================================

I hope that everybody is in agreement up to this point.


Of course, there would not be any problem if it were always possible
to syntactically recognize these uses.  Then the e.g. BEAM compiler
could apply this transformation automatically.  Unfortunately, it is
currently possible to write the following:

t1(PAIR_AS_FUN) ->
  PAIR_AS_FUN(foo,42).

and at runtime call t1/1 as

  t1({?MODULE,f}).

In other words, one can create a "fun" out of a 2-element tuple which
of course implies a runtime check everytime a fun_call is encountered.
Notice that probably the only reason to use this feature is so as to
be able to pass only one argument that is not deconstructed when using
it as a fun.

Questions:

 1. Are there actual uses of this thingie?

 2. Will you feel deprived of something if the support for this
    "feature" is discontinued?

 3. Will you object if this happens soon?


Your input is appreciated.

Best regards,

Kostis Sagonas (for the HiPE group).



Reply | Threaded
Open this post in threaded view
|

Erlang improvement?

Samuel Elliott
On 19/09, Kostis Sagonas wrote:

| Instead, we think that the following syntax is a much better way to
| write the above:
|
| %%===============================================================
|
| t2(M,F) ->
|   M:F(bar,42).
|
| %%===============================================================

Let's assume that f(X) returns 'a' and g(Y) returns 'b'.
Does f(X):g(Y) mean a:g(Y) (call g in module a with parameter Y) or the
function object a:b? Isn't there an ambiguity here?



Reply | Threaded
Open this post in threaded view
|

Erlang improvement?

Robert Virding-4
In reply to this post by Kostis Sagonas-3
Kostis Sagonas <kostis> writes:
>
... Stuff about M:F(...) vs {M,F}(...)
>
>Questions:
>
> 1. Are there actual uses of this thingie?
>
> 2. Will you feel deprived of something if the support for this
>    "feature" is discontinued?
>
> 3. Will you object if this happens soon?

You can actually write the M:F(...) form today (with the caveats in my
previous mail) but the {M,F} form is still allowed for backwards
compatibility.  I don't know if anyone uses it, I never have.  It was
added back in the dark ages before real fun's as a poor man's
functional object, something which was ONE thing which could be
created dynamically, passed around and applied to call a function.
Also it needed no new data types and a very small modifiaction the
emulator.

I would personally have nothing against removing it, but it Ericsson
Erlang group and major uers who decide.  It not anything that I worry
about.

        Robert


Reply | Threaded
Open this post in threaded view
|

Erlang improvement?

Helmut Enck-Radana-2
In reply to this post by Kostis Sagonas-3
At 18:08 19-09-01, Kostis Sagonas wrote:
>t2(M,F) ->
>   {M,F}(bar,42).   %% WEIRD SYNTAX FOR "funs"
>
>[...]
>Instead, we think that the following syntax is a much better way to
>write the above:
>
>t2(M,F) ->
>   M:F(bar,42).

There was a discussion on this list in the past which I think is related to
this subject. See
http://www.erlang.org/ml-archive/erlang-questions/200102/msg00119.html,
http://www.erlang.org/ml-archive/erlang-questions/200102/msg00124.html
and the following discussion.

-- Helmut