views:

57

answers:

2

Is there a way to determine the type of an element within a list in Prolog? I know that variables aren't explicitly typed in Prolog, but I need to check whether an element is a number, a specific character, etc. How can this be accomplished?

+2  A: 

Prolog defines a group of built-in predicates for type testing purposes: var/1, atom/1, integer/1, float/1, atomic/1, compound/1, nonvar/1, number/1, all of them with quite a self-explanatory meaning if you know the data types of the language. For specific characters, you may exploit unification with that character, after checking that the element is not a free variable (otherwise unification is always successful).

Giulio Piancastelli