Erlang:异常case_clause崩溃

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

I ran into a very unusual case_clause match failure when testing my Erlang program.

createPattern(PatternId, Analyzer, PatternDesc) when is_list(PatternDesc) -> 

    F = fun() ->

        case mnesia:wread({patterns, PatternId}) of

            [] ->
                mnesia:write(#patterns{pattern_id = PatternId, analyzer = Analyzer, pattern_desc = PatternDesc}),
                {?RESULT_PASSED, ?REASON_CREATED};

            _ -> {?RESULT_FAILED, ?REASON_EXISTS}
        end
    end,

    case Analyzer of

        {script, ScriptName} -> 
            case io_lib:latin1_char_list(ScriptName) of 
                true -> ok 
            end;

        {erlang, {M, F}} ->
            case utils:loadModule(M, F, 2) of 
                {?RESULT_PASSED, _} -> ok
            end;
    
        {expression, Expression} -> 
            utils:screenExpression(Expression);

        {expression_group, ExpressionGroup} -> 
            utils:screenExpressionGroup(ExpressionGroup)

    end,
  
    mnesia:activity(transaction, F).

I am passing Analyzer with the value {erlang, {plugin, evaluate}}. I am getting a case_clause crash. When I replaced {erlang, {M, F}} with {erlang, {Module, Function}} the match succeeded.
Now it is unusual because the pattern is the same and M and F were not declared prior. So it should match.
I am running erlang 23. What am I missing here?
Thanks.

r9f1avp5

r9f1avp51#

好吧,你之前确实定义了函数F(见下文),也许你想从这个开始。
F = fun() ->

相关问题