[erlang-questions] Beginner

Roger Critchlow rec@REDACTED
Mon Feb 25 11:01:34 CET 2008


Nick --

tailMin isn't a name you can bind to a value, use TailMin instead.

tailMin = 2 asserts that the atom 'tailMin' is equal to the integer 2.

-- rec --

2008/2/25 nick james <nick.james@REDACTED>:

>  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
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080225/9594a83a/attachment.htm>


More information about the erlang-questions mailing list