[erlang-questions] why is the the output not a list

Stefan Schmiedl s@REDACTED
Sat Sep 26 15:36:36 CEST 2015


Roelof Wobben (26.09. 14:44):

> Hello,
> 
> I tried to make a number parser which can parse numbers above the 10.
> 
> So I change my code to this :
> 
> -module(number_parser).
> 
> -export([scan/1]).
> 
> scan(String) ->
>      scan(String, []).
> 
> scan([], List) ->
>      List;
> 
> scan([Head | Rest], List_parse) when Head >= $0, Head =< $9 ->
>       digits(Head, Rest, List_parse);
> 
> scan( [$+ | Rest], List_parse) ->
>     scan(Rest, [$+ | List_parse] );
> 
> scan([32 | Rest], List_parse) ->
>      scan(Rest, List_parse).
> 
> 
> digits(Number, [Head | Rest] , List_parse ) when Rest >= $0 , Head =< 10 ->

                                                   ^^^^ Head

conditions after a "when" fail silently, so you're never going into
this function

s.

>      digits(Number + Head, Rest, List_parse);
> 
> digits(Number, String , List_parse ) ->
>      scan(String, [Number | List_parse]).
> 
> But when I do number_parser:scan("1 + 1") I see this as output "1+1" 
> where I was expecting to see [ [1] . [+],[1]]

> 
> Where did my thinking took the wrong path.
> 
> Roelof
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list