non-Erlang Erlang grammars

Ulf Wiger <>
Mon Oct 23 12:41:15 CEST 2000


I've spent some time pondering the match specifications for trace
and (not yet released) ets. While the functionality is powerful
and much wanted, I think it's really too bad that one can't specify
the filters using Erlang pattern matching syntax, which is already so
familiar.

Also, when speaking of foldl-type operations on ets tables, it would
be really nice if one could write a fun in Erlang which i guaranteed
to be O(1), and thus could be executed efficiently by the VM in an
ets:foldl().

One advantage of the ugly (sorry) match specs is that they can be
generated quite easily from a program I'm working on such a program
right now:

match_conditions([{V1,V2}|Vars], [D|Dims], KeyComps, Pat) ->
    case element(D, Pat) of
        range ->
            K = {{element(D, KeyComps)}},
            [{'=<', V1, K}, {'>', V2, K} |
             match_conditions(Vars, Dims, KeyComps, Pat)];
        {match, upper, X} ->
            [{'==', V2, X} | 
             match_conditions(Vars, Dims, KeyComps, Pat)];
        {match, lower, X} ->
            [{'==', V1, X} | 
             match_conditions(Vars, Dims, KeyComps, Pat)];
        {match, both_equal, Pair} ->
            [{'==', {{V1,V2}}, {Pair}} | 
             match_conditions(Vars, Dims, KeyComps, Pat)]
    end;
match_conditions([], [], _, _) ->
    [].


but I still think there should be a way to achieve this without
departing too much from the standard Erlang grammar.

Lastly:

If we are supposed to write functions to this effect, it would be nice
to have a library function, or BIF, to solve the following:

var( 1) -> '$1';
var( 2) -> '$2';
var( 3) -> '$3';
var( 4) -> '$4';
var( 5) -> '$5';
var( 6) -> '$6';
var( 7) -> '$7';
var( 8) -> '$8';
var( 9) -> '$9';
var(10) -> '$10';
var(11) -> '$11';
var(12) -> '$12';
var(13) -> '$13';
var(14) -> '$14';
var(15) -> '$15';
var(16) -> '$16';
var(17) -> '$17';
var(18) -> '$18';
var(19) -> '$19';
var( N) ->
    list_to_atom([$$|integer_to_list(N)]).

Obviously, I'd rather see that the need for such "hash variables" went
away completely.

/Uffe
-- 
Ulf Wiger                                    tfn: +46  8 719 81 95
Strategic Product & System Management        mob: +46 70 519 81 95
Ericsson Telecom AB,              Datacom Networks and IP Services
Varuvägen 9, Älvsjö,                    S-126 25 Stockholm, Sweden




More information about the erlang-questions mailing list