[erlang-questions] ** exception error: no function clause matching test_calculate:validate(["1", "+", "1"], []) (test_calculate.erl, line 11)

Roelof Wobben r.wobben@REDACTED
Wed Sep 30 17:42:20 CEST 2015


Hello,

I try to make a little parser which parse calculations.

So so far I have this code :

-module(test_calculate).

-export([validate/1]).

scan(String) ->
     validate(string:tokens(String, " ")).

validate(String) ->
     validate(String, []).

validate([Head | Tail], Validated_list) when Head >= $0 , Head =< $9 ->
     validate(Tail, [Head | Validated_list]);

validate([Head | Tail], Validated_list) when Head =:= $+ ->
     validate(Tail, [Head | Validated_list]);

validate([], Validated_list) ->
     Validated_list.

test() ->
     ["1","+","1"]    = scan("1 + 1"),
     ["10", "+", "1"] = scan("10 + 1"),
     ["1", "+", "10"] = scan("1 + 10"),
     io:format("All tests are green ~n").

but as soon as I try :

test_calculate:validate(["1","+", "1"])

I see the above error

Someone a tip where things are going the wrong way ?

Roelof




More information about the erlang-questions mailing list