How to fix error on tolowercase implementation prolog?

Viewed 48

I'm trying to create a tolower implementation in prolog, but i keep getting an error and I'm not sure what it means.

?- tolower("HE",L).    
ERROR: tolower/2: Undefined procedure: (+)/2

here is my implementation so far.

tolower([], _).
tolower([H|T], L):-
    H + 32, tolower(T, L).
1 Answers

Let us see what H + 32 means:

?- write_canonical(H+32).
+(_,32)

So you are invoking a predicate called +, with two arguments.

You have not defined such a predicate, hence you get an error.

To evaluate arithmetic expressions, use for example a constraint such as (#=)/2 for integers:

R #= H + 32

This is a relation, saying that R is equal to H + 32, evaluated as an integer expression.

Depending on your Prolog system, you may have to import a library to use (#=)/2.

Related