Hi,
Why does this goal evaluate to true ?
?- [1] =:= 1
true
Hi,
Why does this goal evaluate to true ?
?- [1] =:= 1
true
I suspect it is this one. The docs talk about chars and one-character atoms but I am guessing that using an integer is also accepted. You can also do this:
?- ['1'] =:= 49.
true.
?- `1` =:= 49.
true.
?- "a" =:= 97.
true.
Ok, it is a suprising behavior
thank you Boris for your answer
Sicstus docs says:
[X]
A list of just one number X evaluates to X. Since a quoted string is just a list of integers, this allows a quoted character to be used in place of its character code; e.g."A"
behaves within arithmetic expressions as the integer 65.
Why does this goal evaluate to true ?
I suppose that this is informally a convention that the early Prolog implementations adopted.
Note that quoted strings may work differently in SWI
Yes, “a” maps to a string, but arithmetic evaluation evaluates a string with a single character as the character code of that character, so A is "a"
still gets you the character code for a
. Modern code should use 0'a
instead. That is handled by the parser and read as 97
.