假设在 metapost 中可能有一个具有特定名称的宏,也可能没有,并且根据具体情况,代码的行为需要以某种方式改变。如下所示:
vardef something (expr someargument) = someargument**2 enddef;
%vardef somethingElse (expr someargument) = someargument**3 enddef;
vardef doesItExist@# =
% the code for the check goes here
enddef;
if doesItExist.something:
fill fullcircle scaled 2cm withcolor red;
else:
fill fullcircle scaled 2cm withcolor green;
fi; % should produce a red circle
if doesItExist.somethingElse:
fill fullcircle scaled 1cm withcolor red;
else:
fill fullcircle scaled 1cm withcolor green;
fi; % should produce a green circle
这能做到吗?