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

Roelof Wobben r.wobben@REDACTED
Sat Sep 26 14:44:17 CEST 2015


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 ->
     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




More information about the erlang-questions mailing list