【发布时间】:2012-03-07 04:45:07
【问题描述】:
有没有办法使用匹配规范在函数的不同子句之间进行选择?我见过匹配规范仅用于跟踪或匹配 ets 表中的条目。
我想做的例子:
在用户提供的文件中:
Module(m1),
Function(f1),
Guard([ %% list of match specifications follows:
%% First (and only in this case) match spec:
{ [{score, '$1', '$2', '$3'}, '$4'],
[{is_atom, '$1'}, {is_pid, '$2'}, {is_atom, '$3'}],
[true] }
]).
我想从这个文件生成代码。对我来说重要的是能够使用 Guard 中的匹配规范来过滤掉 f1 的子句,这样我就可以知道 f1 的第一个参数何时是 {score, First, Second,第三}和is_atom(First)、is_pid(Second)、is_atom(Third)。
有没有办法让我生成这样的代码:
case some_unknown_function(MatchSpec, F1Args) of
true ->
%% f1's clause matches the MatchSpec
;
false ->
%% f1's clause does not match the MatchSpec
end.
任何帮助将不胜感激。谢谢。
【问题讨论】:
标签: erlang