[erlang-questions] list comprehensions with predefined functions?

Jilani Khaldi <>
Wed Jun 18 15:53:37 CEST 2008


Andreas Hillqvist wrote:
> Try:
>  > [mymath:power(X, Y) || X <- [1,2,3] Y <- 3].
Try:
[mymath:power(X, Y) || X <- [1,2,3], Y <- [3]].
[mymath:power(X, Y) || X <- [1,2,3], Y <- [3, 4]].

% modify N in -N for N < 0
power(N, P) when is_integer(N), N >= 0 -> ipower(N, P, 1);
power(N, P) when is_integer(N), N < 0 -> 1/ipower(-N, P, 1).
ipower(0, _, R) -> R;
ipower(N, P, R) -> ipower(N-1, P, R*P).

-- 
Jilani KHALDI
---------------------
http://www.jkhaldi.eu



More information about the erlang-questions mailing list