I have this fact in my base fact("name","surname","123"). if i simply write this question: fact(X,_,_). For X I get some unidentified output. How can I retrieve any of this values, 开发者_运维问答or how to get this output? ?-fact(X,_,_). output: name.
Thanks ahead.
In SWI-Prolog you can use string_to_atom/2
:
?- assert(fact("name", "surname", "123")).
true.
?- fact(Tmp, _, _), string_to_atom(Tmp, X).
Tmp = [110, 97, 109, 101],
X = name.
Strings in Prolog are enclosed within single quotes. When you use double quotes it means that you want the list of character codes.
?- is_list('abc').
false.
?- is_list("abc").
true.
?- write("abc").
[97,98,99]
true.
?- write('abc').
abc
true.
try this,
| ?- assert(fact("name", "surname", "123")).
yes
| ?- fact(X,_,_).
X = [110,97,109,101];
| ?- fact(_X,_,_),name(Y,_X).
Y = name;
精彩评论