[eeps] allow external function as literals

Richard A. O'Keefe ok@REDACTED
Thu Oct 2 01:02:58 CEST 2014


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

The obvious questions are
(1) Do we really have a problem?
(2) If we have a problem, is *this* the problem we really have?

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?

As far as I know, {Module,Name} pairs still work as 
functions:

1> F = {erlang,now}.
2> F().

So you could replace fun ffe:docol/4 by {ffe,docol}.
What difference does it make?

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.

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





More information about the eeps mailing list