Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from May 24, 2013

Conversation

Projects
None yet
2 participants
Contributor

doubleyou commented Nov 24, 2011

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

Contributor

doubleyou commented Nov 24, 2011

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
Owner

uwiger commented Nov 29, 2011

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 uwiger merged commit e76c5f3 into uwiger:master May 24, 2013

Owner

uwiger commented May 24, 2013

I finally merged this. Sorry about the delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment