Bang Bang
Joe Armstrong
joe@REDACTED
Tue Jan 13 11:25:39 CET 2004
Oh dear, sorry it's not *pure* erlang :-)
If the great maintainers add the following line to erl_parse.yrl
-----
expr_100 -> expr_150 '!' '!' expr_100: {call, line('$1'),
{remote, line('$1'),
{atom, line('$1'),sysd},
{atom, line('$1'),rpc}},
['$1', '$4']}.
-----
then it would be standard Erlang :-)
Users would be free to define their own sysd:rpc
((possibly even better is to exapand this into ?MODULE:rpc/2))
The change is purely *local* - if you "make" everything a new versions of
erl_parse.erl{.beam} are put into the /widgets subdirectory.
Pid !! X is just expanded into
sysd:rpc(Pid, X).
This make the code (IMHO) very pretty
The code to swap the values in two entries, is thus ...
Entry1 = Win !! mkEntry(....)
Entry2 = Win !! mkEntry(...)
Button = Win !! mkButton(....)
...
Swap = fun(_) ->
Str1 = Entry1 !! read,
Str2 = Entry2 !! read,
Entry1 ! {set, Str1},
Entry2 ! {set, Str2}
end,
Button ! {onClick, Swap}
...
To my mind this code is very clear and beautiful.
We could even see at a glance that
Entry !! read
is a possible error (ie it should be)
Var = Entry !! read
ie why do an rpc and NOT store the value - if you *wanted* to
read the value but not get a return value you could write
Entry ! read
Instead ....
Converting this to rpc(Entry, read) etc is a lot uglier.
<<aside>>
It's a pity I had to change the parser to do this.
I can't do this with -parse_transform(...) because parse transform
only works with correctly parsed forms and !! is not a correct form.
What one needs is
-token_transform(Mod).
Which transforms the input token stream prior to parsing.
/Joe
On Tue, 13 Jan 2004, mats cronqvist wrote:
> thought i try ex11, but then i saw this;
> "!! is an infix RPC operator. This needs a ONE LINE change to
> erl_parse.yrl which makes a new version of erl_parse.erl"
> so only people that willing/able to rebuild erl_parse can try ex11. i
> for one am not (willing, that is).
> but maybe a sed script or something can convert the code to erlang?
>
> mats
>
More information about the erlang-questions
mailing list