Prolog: single item and list of individual items

By eliminating the more difficult task for the school, I discovered a mistake that I made when I was processing a single list of items (a stack with one item), as if it were a separate item. I solved my problem, however during further testing I noticed something strange:

48 ?- 1 is [1].
true.

49 ?- -1 is [-1].
ERROR: is/2: Type error: `character' expected, found `-1'

50 ?- 0.66 is [0.66].
ERROR: is/2: Type error: `character' expected, found `0.66'

A similar behavior occurs using =: = / 2 instead of is / 2. Therefore, for some reason, one list of elements is considered the same as one element, but only for non-negative integers.

Curiosity is more than anything ... does anyone know why this is?

Thank!

+5
source share
1 answer

SWI-Prolog (, , ), is/2 =:=/2:

.(+Int,[])

A list of one element evaluates to the element. This implies "a" evaluates to 
the character code of the letter `a' (97). This option is available for 
compatibility only. It will not work if `style_check(+string)' is active as "a"
will then be transformed into a string object. The recommended way to specify the
character code of the letter `a' is 0'a.

, , , , , .

+4

All Articles