Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Erlang 返回真或假查找子字符串_Erlang - Fatal编程技术网

Erlang 返回真或假查找子字符串

Erlang 返回真或假查找子字符串,erlang,Erlang,我只是想弄清楚控制流,这一切都非常奇怪和混乱,因为我以前从未使用过函数式语言,有人能帮我纠正一下吗: -export([main/1, test/2]). main([]) -> if test("blue yellow green", "yellow") == true -> {io:fwrite("found")}; true -> {io:fwrite("not found")} end.

我只是想弄清楚控制流,这一切都非常奇怪和混乱,因为我以前从未使用过函数式语言,有人能帮我纠正一下吗:

-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. 
更正版本:

-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.
仅返回一个元素时,不应使用
{
}

更正版本:

-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.

当您只返回一个元素时,不应该使用
{
}

我可能会使用
大小写字符串:当p>=1->true时,p的str(Source,Find);0->false end
在这里或类似的地方,甚至只是
字符串:str(Source,Find)>=1。
这个答案只有一个问题。如果字符串看起来像这样,您仍然会得到一个0返回
字符串:str(“蓝-黄-绿”,“蓝”)。
。如果您知道您要查找的内容永远不会从char 0开始,这不是什么大问题。当P>=1->true时,我可能会使用P的
大小写字符串:str(Source,Find);0->false end
在这里或类似的地方,甚至只是
字符串:str(Source,Find)>=1。
这个答案只有一个问题。如果字符串看起来像这样,您仍然会得到一个0返回
字符串:str(“蓝-黄-绿”,“蓝”)。
。这不是一个大问题,如果你知道你要找的东西永远不会从0开始。