

This is the "comparison operator for string things"
Suppose you have received a "stringy thing".
How do you compare it against a known atom while not worrying about the actual underlying type? Using this predicate!
atom_string(known,StringyThing)
will compare against atom known
, doing all conversions for you!
Doc-needs-help
atom_string/2 takes anytext (as explained here), and these also succeed:
Note: Backticks is the notation for a "list of character codes" (unless Prolog is running with the 'traditional' flag):
?- X=`alpha`. X = [97,108,112,104,97].
Then:
atom_string(`alpha`,"alpha"). atom_string("alpha",`alpha`).
Similarly for lists of characters or "chars":
?- atom_chars(hello,X),atom_string(X,hello). X = [104,101,108,108,111]. ?- atom_chars(hello,X),atom_string(hello,X). X = [104,101,108,108,111].
Conversion!
Making clear the intention of using atom_string/2 by splitting its functionality:
% clause 1: just need to make sure X is nonvar (groundedness etc are checked by atom_string/2) % clause 2: raise exception if X is a var convert_to_string(X,Str) :- nonvar(X),!,atom_string(X,Str). convert_to_string(X,_) :- var(X),!,instantiation_error(X). convert_to_atom(X,Atom) :- nonvar(X),!,atom_string(Atom,X). convert_to_atom(X,_ ) :- var(X),!,instantiation_error(X).
Yup! Those go into the toolbag!
Hmmm...
Here is a Test case for illustration/documentation purposes
Note that atom_string/2 does not really behave "predicate-ly" but more like a two-sided pipeline.
Send in anything "stringy" ------>+ +---------> String equivalent of the input | | atom_string(?Atom, ?String)
Atom equivalent of the input <----+ +<------ Send in anything "stringy" | | atom_string(?Atom, ?String)
Send in anything "stringy" ------>+ +<------ Send in anything "stringy" | | atom_string(?Atom, ?String) | | "true if stringily equivalent"
Maybe these predicates which accepts several representations of the "same thing" should be thought of as operating on equivalence classes but returning a preferred representative of the equivalence class depending on the argument, whereas verification can work with any representative of the equivalence class!