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

Roelof Wobben <>
Wed Sep 30 21:33:13 CEST 2015


Op 30-9-2015 om 18:01 schreef Hugo Mills:
> On Wed, Sep 30, 2015 at 05:42:20PM +0200, Roelof Wobben wrote:
>> 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, " ")).
>     string:tokens/2 expects its first parameter to be a string (i.e. a
> list of integers representing the character codes of the elements of
> the string).
>
> [snip]

Correct, that is why string:tokens is called with as parameter "1 + 1 ".
>> test_calculate:validate(["1","+", "1"])
>     What is this parameter? Is it what string:tokens/2 is expecting?

This is the outcome of the string:token with as argument "1 + 1 ".

>     Brief exercise for you: how does erlang represent each of the
> following? Write each one as a term without string notation, and as a
> string (if it can be written as a string).
>
> [53]
> "5"
> $5
> [$5]
>
>     Hugo.

[53]     "5"
"5"      "5"
$5       "53"
[$5]     "5"






More information about the erlang-questions mailing list