在erlang中比较宏中的两个字符串时程序出错

rav*_*_ss 2 erlang erlang-shell

我已经编写了宏来比较两个字符串,如下所示

-module(helloworld). 
-export([start/0]). 
-define(macro1(X,Y),{if X == Y -> "True"; true ->"False" end.}). 

start() ->
   io:fwrite("~w",[?macro1("str","str")]).
Run Code Online (Sandbox Code Playgroud)

得到错误如下:

Compiling the source code....
$erlc helloworld.erl 2>&1
helloworld.erl:6: syntax error before: '.'
helloworld.erl:2: function start/0 undefined
Run Code Online (Sandbox Code Playgroud)

Pas*_*cal 5

宏不像函数定义。预处理器只是进行字符串替换。所以在你的情况下,你必须删除大括号中的点:

-define(macro1(X,Y),{if X == Y -> "True"; true ->"False" end}). 
Run Code Online (Sandbox Code Playgroud)