2011-06-28 60 views
9

這裏使用本地功能的方式是我的代碼:是否有警衛

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

problem_7(Current, Primes, Counter) when Primes >= 10001-> 
    Current; 
problem_7(Current, Primes, Counter) when is_prime(Counter) -> 
    problem_7(Counter, Primes + 1, Counter + 1); 
problem_7(Current, Primes, Counter) -> 
    problem_7(Current, Primes, Counter). 

我得到錯誤:

32> c(problem_7). 
./problem_7.erl:30: call to local/imported function is_prime/1 is illegal in guard 

,我不能在「if'表達使用本地功能:

if is_prime(Counter)-> 
    problem_7(Counter, Primes + 1, Counter + 1); 
    true -> 
    problem_7(Current, Primes, Counter + 1) 
end. 

我只是想知道是否有任何方式使用本地功能在後衛,我怎麼能寫本地功能的條件?

回答