It is a tiny parse transform.
License: MIT
Author: Uvarov Michael ([email protected])
-compile({parse_transform, mead}).
From lists
(Erlang/OTP).
Before:
usplit_1(X, Y, [Z | L], R, Rs) when Z > Y ->
usplit_1(Y, Z, L, [X | R], Rs);
usplit_1(X, Y, [Z | L], R, Rs) when Z == Y ->
usplit_1(X, Y, L, R, Rs);
usplit_1(X, Y, [Z | L], R, Rs) when Z > X ->
usplit_1(Z, Y, L, [X | R], Rs);
usplit_1(X, Y, [Z | L], R, Rs) when Z == X ->
usplit_1(X, Y, L, R, Rs);
usplit_1(X, Y, [Z | L], [], Rs) ->
usplit_1(X, Y, L, [Z], Rs);
usplit_1(X, Y, [Z | L], R, Rs) ->
usplit_1_1(X, Y, L, R, Rs, Z);
usplit_1(X, Y, [], R, Rs) ->
rumergel([[Y, X | R] | Rs], [], asc).
After:
usplit_1(X, Y, [Z | L], R, _) when Z > Y -> me(Y, Z, L, [X | R], _);
usplit_1(_, Y, [Z | L], _, _) when Z == Y -> me(_, Y, L, _, _);
usplit_1(X, _, [Z | L], R, _) when Z > X -> me(Z, _, L, [X | R], Rs);
usplit_1(X, _, [Z | L], _, _) when Z == X -> me(X, _, L, _, _);
usplit_1(_, _, [Z | L], [], _) -> me(_, _, L, [Z], _);
usplit_1(X, Y, [Z | L], R, Rs) ->
usplit_1_1(X, Y, L, R, Rs, Z);
usplit_1(X, Y, [], R, Rs) ->
rumergel([[Y, X | R] | Rs], [], asc).
From cyrsasl_digest
(ejabberd).
Before:
parse1([$= | Cs], S, Ts) ->
parse2(Cs, lists:reverse(S), "", Ts);
parse1([$, | Cs], [], Ts) ->
parse1(Cs, [], Ts);
parse1([$\s | Cs], [], Ts) ->
parse1(Cs, [], Ts);
parse1([C | Cs], S, Ts) ->
parse1(Cs, [C | S], Ts);
parse1([], [], T) ->
lists:reverse(T);
parse1([], _S, _T) ->
bad.
After:
parse1([$= | Cs], S, Ts) -> parse2(Cs, lists:reverse(S), "", Ts);
parse1([$, | Cs], [], _) -> me(Cs, _, _);
parse1([$\s | Cs], [], _) -> me(Cs, _, _);
parse1([C | Cs], S, _) -> me(Cs, [C | S], _);
parse1([], [], T) -> lists:reverse(T);
parse1([], _S, _T) -> bad.
This parse transform adds the hidden arguments.
Source code:
map(X, [H|T]) ->
[F(H)|map(X, T)];
map(F, []) ->
[].
Code after this parse transform:
map(_1 = X, _2 = [H|T]) ->
[F(H)|map(X, T)];
map(_1 = F, _2 = []) ->
[].
fun_me()
- returns the current function as a HOF (fun F/A);my_arguments()
- returns arguments as a list;my_name()
- returns the name of the current function;my_arity()
- returns the count of arguments of the current function.
These functions can be used for formatting debug messages.
response(KeyVals, User, Passwd, Nonce, AuthzId, A2Prefix) ->
%% debug
error_logger:info_msg("[~s~s] Args: ~w~n",
[?MODULE, my_name(), my_arguments()]),
...