PLOGHELP NAME Robert Duncan, June 1988 ?- name(Item, CharList). Conversion between atomic terms and character strings. In this goal, CharList is the list of ASCII characters which make up the atomic term Item. For instance: ?- name(example, "example"). yes By leaving CharList wholly or partly uninstantiated, it is possible to decompose an atom into its constituent characters, as in: ?- name(example, X). X = [101, 120, 97, 109, 112, 108, 101] ? yes Alternatively, if Item is left uninstantiated, then an atom will be constructed from CharList and assigned to Item. ?- name(X, "example"). X = example ? yes In this case, it is an error for CharList to be anything other than a proper string. As an example, here is the definition of a predicate which removes the extension from a file name, i.e. everything after the "." character: basename(F, F1) :- name(F, S), append(S1, [46|Ext], S), % 46 is the ASCII code for "." name(F1, S1). ?- basename('temp.pl', X). X = temp ? yes Item may be any atomic term, not just a pure atom. This includes numbers, together with any data objects imported from other languages (such as Lisp or POP-11). In these cases, CharList will be unified with the characters which make up the printing representation of Item. For example: ?- name(12.33, X). X = [49, 50, 46, 51, 51] ? yes In general of course, it is impossible to do the inverse of this decomposition, as an arbitrary data object cannot possibly be reconstructed simply from its printing representation. However, a special case is made for integers: whenever CharList contains only digit characters, Item will be instantiated to the integer value of the digit string, as in: ?- name(N, "999"), integer(N). N = 999 ? yes -- RELATED DOCUMENTATION ---------------------------------------------- PLOGHELP * STRINGS Strings in Prolog PLOGHELP * UNIV Conversion between complex terms and lists --- C.all/plog/help/name ----------------------------------------------- --- Copyright University of Sussex 1988. All rights reserved. ----------