带有双问号的Erlang宏

bxjv4tth  于 2022-12-08  发布在  Erlang
关注(0)|答案(1)|浏览(211)

我知道宏定义为as follows

-define(Const, Replacement).
-define(Func(Var1,...,VarN), Replacement).

但是这个带双问号的代码是如何表示的呢?我应该如何理解它呢?

-define(Assign(Var,Exp), Var=Exp, io:format("~s = ~s -> ~p~n", [??Var, ??Exp, Var] )).

start() ->
   ?Assign(X, lists:sum([1, 2, 3])).

其输出为:

X = lists : sum ( [ 1 , 2 , 3 ] ) -> 6
aiazj4mn

aiazj4mn1#

经过搜索,我找到了它。Stringifying Macro Arguments

The construction ??Arg, where Arg is a macro argument, 
will be expanded to a string containing the tokens of the argument. 
This is similar to the #arg stringifying construction in C.

The feature was added in Erlang 5.0/OTP R7.

相关问题