[erlang-questions] or?

Pablo Polvorin <>
Wed Jun 18 20:01:57 CEST 2008


fib(N) ->
     if
             N > 1 ->
                        fib(N-1) + fib(N-2);
             N == 1;
             N == 0 ->
                        N
        end.

Or using brackets:
fib2(N) ->
     if
             N > 1 ->
                        fib2(N-1) + fib2(N-2);
             (N == 1) or (N == 0) ->
                        N
    end.

written in more idiomatic erlang:

fib3(0) -> 0;
fib3(1) -> 1;
fib3(N) when N > 1 ->   fib3(N-1) + fib3(N-2).




2008/6/18, Circular Function <>:
> if i instead of :
>
> fib(N) ->
>         if
>                 N > 1 ->
>                         fib(N-1) + fib(N-2);
>                 N == 1 ->
>                         1;
>                 N == 0 ->
>                         0
>         end.
>
> want to do:
>
> fib(N) ->
>         if
>                 N > 1 ->
>                         fib(N-1) + fib(N-2);
>                 N == 1 or N == 0 ->
>                         N
>         end.
>
> it doenst work, how do i use or?
> http://www.erlang.org/doc/reference_manual/part_frame.html
> doesnt provide an actual example of how to use it.
>
>
>
>       __________________________________________________________
> Ta semester! - sök efter resor hos Yahoo! Shopping.
> Jämför pris på flygbiljetter och hotellrum här:
> http://shopping.yahoo.se/c-169901-resor-biljetter.html?partnerId=96914052


-- 
--
pablo
http://ppolv.wordpress.com
----



More information about the erlang-questions mailing list