I'm quite new to Prolog and I stumbled on something that I don't understand.
This is my code:
:- dynamic user/3.
user('id', 'Name', 20).
changeAge(Id, NewAge) :-
user(Id, Name, _),
retract(user(Id,_,_)),
assert(user(Id,Name,NewAge)).
To update user information in the database,
changeAge/2
performs these three steps:
- Lookup a right record, using
user/3
. - Remove one matching record from the database, using
retract/1
. - Insert a new updated record into the database, using
assert/1
.
This is my console output:
1 ?- user('id', _, Age).
Age = 20.
2 ?- changeAge('id', 25).
true.
3 ?- user('id', _, Age).
Age = 25.
4 ?- changeAge("id", 30).
false.
5 ?- user('id', _, Age).
Age = 25.
Why do single quotes give me true
(line 2)
when double quotes give me false
(line 4)?