This also is the "comparison operator for stringy 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].
Test case
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" (implies equivalence classes across types)
A generic replacement
A module providing a replacement for
with a type-information taking/providing predicate stringy_morph/4
and a replacement for all of
with a type-information taking/providing predicate stringy_charylist_morph/4
On this page: