[eeps] allow external function as literals

Tony Rogvall tony@REDACTED
Thu Oct 2 08:36:40 CEST 2014


On 2 okt 2014, at 01:02, Richard A. O'Keefe <ok@REDACTED> wrote:

> 
> On 2/10/2014, at 10:55 AM, Tony Rogvall wrote:
>> In a toy project
> 
> The obvious questions are

Not at all obvious to me.

> (1) Do we really have a problem?

My obvious question is who are we?

> (2) If we have a problem, is *this* the problem we really have?
> 
Yes we have, regardless of who we are.

> Ad 1, why does it *matter* whether tuples containing
> fun mod:nam/ari terms are compiled as stored-once literals
> or not?  What is the measured difference it makes to the
> performance of a realistic program?

I guess the answer is yes in at least two ways.

The produced code is not a literal, as I tried to explain.
The performance impact is enormous. The term is built every call.
and I had intend to do a lot of them.

> 
> As far as I know, {Module,Name} pairs still work as 
> functions:
> 
> 1> F = {erlang,now}.
> 2> F().
> 
The answer is NO. The extern fun is nothing close to this (I am just joking), is is close
but it is much more efficient since it creates and export entry (check internals if you like)
that is ready to be used and does not have to lookup the function every time.

> So you could replace fun ffe:docol/4 by {ffe,docol}.
> What difference does it make?
> 
As explained above, a lot.

> Ad 2, perhaps what we *really* want is an analogue of
> Eiffel's "once" features, or the pthread_once() function
> in POSIX.  Here's what I have in mind.
> 
This is a really bad idea. Why add extra declaration to a language that is 
,still, small and slim. The fix is to make literals (or potential literals) as literals.

> -once.
>> '_ffe_sqr'() ->
>>    { 0, <<"sqr">>, fun ffe:docol/4,
>>      fun ffe:dupe/0, fun ffe:star/0, 
>>      fun ffe:semis/0 }.
>> 
> -once.
>> '_ffe_sum'() ->
>>    { 0, <<"sum">>, fun ffe:docol/4,
>>      fun ffe:lit/0,  1,
>>      fun ffe:pqdo/0, 4,
>>        fun ffe:plus/0, 
>>      fun ffe:ploop/0, -2, 
>>      fun ffe:semis/0 }.
> 
> The idea here is that the directive -once says
> - the next thing must be a function declaration
> - with no arguments
> - and one clause
> - containing no send "!" or "receive" or self()
> The first time a once function is called after its containing
> module is loaded, its value will be computed, and then stored
> in some persistent fashion, which will be deleted when the
> module is.
> 
> This is a (conceptually!) simple general mechanism with
> lots of use cases.
> 


No. We do not need this! This is like an initialization of a static variable in C code?

/Tony




More information about the eeps mailing list