[erlang-questions] Beginner

nick james nick.james@REDACTED
Mon Feb 25 10:46:32 CET 2008


Hi,

    I have a program which results in a run time error I don't understand.
The program is:

 

-module(lists1).

-export([min/1]).

 

min(N) when number(N) ->

    N;

 

min([H|[]]) ->

    H;

 

min([H|T]) ->

    tailMin = min(T),

    if

        tailMin > H -> 

            H;

        tailMin =< H -> 

            tailMin

    end

.

 

And the output is:

Eshell V5.6  (abort with ^G)

1> c(lists1).

{ok,lists1}

2> lists1:min(1).

1

3> lists1:min([1]).

1

4> lists1:min([1,2]).

** exception error: no match of right hand side value 2

     in function  lists1:min/1

5>

 

My expectation is that lists1:min([1,2]) would be picked up by min([H|T]) .
Can anyone enlighten me?

 

Nick James
Cadar Measurement Solutions Ltd
tel 08453 708 709
Registered in England, no.2027817, 100 Fitzwalter Road, Sheffield S2 2SP

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080225/abf04ec1/attachment.htm>


More information about the erlang-questions mailing list