0

私は制御フローを理解しているだけです。これまで関数型言語を使用したことがないので、そのすべてが非常に奇妙で混乱しています。誰かが私のためにこれを修正できますか?

-export([main/1, test/2]).

main([]) -> 
   if 
      test("blue yellow green", "yellow") == true ->
          {io:fwrite("found")};
      true ->
          {io:fwrite("not found")}
   end.


test(Source, Find) ->
    Pos = string:str(Source, Find),
    if
       Pos > 1 ->
            {true};  
       true ->
            {false}
    end. 
4

1 に答える 1

3

修正されたバージョン:

-module(test).
-export([main/0, test/2]).

main() ->
    case test("blue yellow green", "yellow") of
        true -> io:fwrite("found~n");
        false -> io:fwrite("not found~n")
    end.

test(Source, Find) ->
    Pos = string:str(Source, Find),
    if
        Pos > 1 ->
            true;
        true ->
            false
    end.

要素を1つだけ返す場合は、andを使用{しないでください}

于 2013-01-22T10:48:24.533 に答える