uwiger / gproc

Extended process registry for Erlang
Apache License 2.0
1.07k stars 232 forks source link

An ability to use {n, l, "something} ! Msg #12

Closed doubleyou closed 11 years ago

doubleyou commented 12 years ago

Hi, Ulf. Since you thought that the idea is worth a try, I decided to make a pull request instead :)

The implementation I've mentioned at the issues was incomplete, so don't mind it. The code of parse transform is completely stolen from erl_id_trans.erl, I've just added 2 lines: https://github.com/doubleyou/gproc/blob/master/src/gproc_pt.erl#L450

doubleyou commented 12 years ago

What else I think can be done here:

  1. The entire parse transform can be simplified, but I'm not sure it's necessary.
  2. Personally, I don't like using {n, l, Term} for this case, using just Term would be nicer. However, this will make us to look up at both local and global namespaces, and name clashes won't be acceptable.
  3. Adding another clause to gproc:send/2 seems kind of ugly, but I didn't see a better way to handle classic message sending operations.
  4. Probably, need to update header of gproc_pt.erl
uwiger commented 12 years ago

Hi,

I am not particularly fond of erl_id_trans.erl, since it needs to be ported every time the language grammar changes a bit (which, admittedly, is not that often).

One can either use parse_trans or syntax_tools, or write something along the lines of:


-module(xform).
-export([parse_transform/2]).

parse_transform(Forms, _Options) ->
    do_transform(Forms).

do_transform([{op, L, '!', Lhs, Rhs} = F|Fs]) ->
    [NewLhs] = do_transform([Lhs]),
    [NewRhs] = do_transform([Rhs]),
    [{call, L, {remote, L, {atom, L, gproc}, {atom, L, send}},
        [NewLhs, NewRhs]} | do_transform(Fs)];
do_transform([]) ->
    [];
do_transform([F|Fs]) when is_tuple(F) ->
    [list_to_tuple(do_transform(tuple_to_list(F))) | do_transform(Fs)];
do_transform([F|Fs]) ->
    [do_transform(F) | do_transform(Fs)];
do_transform(F) ->
    F.

which is very stable even in the face of grammar changes, and therefore works with just about any version of erlang.

uwiger commented 11 years ago

I finally merged this. Sorry about the delay.