[erlang-questions] power(N,P), cant get it to work

Circular Function circularfunc@REDACTED
Tue Jun 17 09:21:41 CEST 2008


-module(math).
-export([fac/1, sq/1,cube/1,power/2]).

fac(N) when N>0 ->
        N * fac(N-1);
fac(0) ->
        1.
    
sq(X) -> X*X.

cube(X) -> X*X*X.

power(N,P) ->
        if P==0 ->
                1;
        true ->
                if P>0 ->
                        N * power(N,P - 1);
                true ->
                        1 / power(N,-1 * P).


Erlang (BEAM) emulator version 5.6.2 [async-threads:0]

Eshell V5.6.2  (abort with ^G)
1> c(math).
../math.erl:20: syntax error before: '.'
../math.erl:2: function power/2 undefined
error
2> 


am i using the "true ->" correctly? it is like else right?



      __________________________________________________________
Går det långsamt? Skaffa dig en snabbare bredbandsuppkoppling. 
Sök och jämför hos Yahoo! Shopping.
http://shopping.yahoo.se/c-100015813-bredband.html?partnerId=96914325
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080617/a4a81d64/attachment.htm>


More information about the erlang-questions mailing list