1

I have used the following logic for above program but it gives error showing >=/2: Arithmetic: 'a/0' is not a function. What should i do to correct the program?

digit(X):- X>=0,X<10,write('input is digit').
uppercase(X):- X>='A',X<'[',write('input is uppercase').
lowercase(X):- X>='a',X<'{',write('input is lowercase').

Thanks

1 Answer 1

1

If you want to classify just the ASCII characters in ISO Prolog, you can do this in various ways:

As characters which are represented as atoms of length 1. To compare them you can use the general term comparison (@>=)/2, (@>)/2 ... In your example, that would be:

digit_char(X) :- atom_length(X,1), X @>= '0', X @=< '9'.
...

As character codes which are plain integers representing the collating sequence integer (sounds impressive? Its just the ASCII-code).

digit_code(X) :- integer(X), X >= 0'0, X =< 0'9.
...

If you need to convert between both, there is char_code/2.

For Unicode, things are not yet generally available and agreed upon. In SWI, there is char_type/2 and code_type/2. Beware, these things are still evolving...

For more about characters and codes, see What is the difference between ' and " in Prolog?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.