Is there a way to use local function in guard

前端 未结 1 519
Happy的楠姐
Happy的楠姐 2021-01-17 15:49

Here is my code:

is_prime(Num)->
    length(list_of_dividers(Num)) == 0.

problem_7(Current, Primes, Counter) when Primes >= 10001->
    Current;
pr         


        
相关标签:
1条回答
  • 2021-01-17 16:04

    The reason for restricting the set of valid expressions is that evaluation of a guard expression must be guaranteed to be free of side effects. http://www.erlang.org/doc/reference_manual/expressions.html (section 7.24)

    Use case statement inside your function. You should be able to use local function in if and case.

    Edited: Agree with @cthulahoops, I was wrong about if http://www.erlang.org/doc/reference_manual/expressions.html#id75927

    0 讨论(0)
提交回复
热议问题