Did you know ... Search Documentation:
Pack onepointfour_basics -- prolog/stringy_and_charylist_type.pl
PublicShow source

This code is specific to SWI-Prolog, as that Prolog provides the traditional "atom" and the non-traditional "string" as two distinct representations of "sequences of characters".

We introduce the following additional vocabulary:

  • A stringy term is a term that is either an atom or a string. In SWI-Prolog, the string is a distinct representation of a sequence of characters, distinct from the atom and mean to be used in text processing rather than as basis for identifiers.
  • A chary term is a term that is either a char (an atom of length 1) or a code (an integer and, more precisely in SWI-Prolog, a Unicode code point).
  • A charylist is less precise: it is a proper list of either codes or chars. It may or may not contain uninstantiated elements. An empty list is a charylist but we cannot know whether it is supposed to be composed of codes or chars. A list containing only uninstantiated variables is also a charylist and again we don't know what it is supposed to contain, at least not yet.

Homepage for this code

https://github.com/dtonhofer/prolog_code/blob/main/unpacked/onepointfour_basics/README_stringy_and_charylist_type.md

History

  1. 2020-07-XX: First code elements created.
  2. 2021-06-08: Re-created from existing code lying around.
  3. 2021-06-11: Back up on github.
 charylist_type(@CharyList, ?Type)
Determine the type of a charylist. It will be one of the following atoms or compound terms or else the predicate will fail (it doesn't throw, i.e. behaves "smoothly"). Note that CharyList must be proper list, partial lists are rejected.
  • var : charylist is uninstantiated
  • empty : charylist is the empty list (no info whether chars or codes)
  • chars(N) : charylist is nonempty and consists of N chars
  • codes(N) : charylist is nonempty and consists of N codes
  • chars_vars(N,V) : charylist is nonempty and consists of N chars and V vars
  • codes_vars(N,V) : charylist is nonempty and consists of N codes and V vars
  • vars(V) : charylist is nonempty and consists of V vars
 stringy_type(@Stringy, ?Type)
Determine the type of Stringy. Type can be string or atom or var, the latter indicating that Stringy is uninstantiated. This predicates behaves softly, i.e. preferentially fails on bad input.
 stringy_type_with_length(@Stringy, Type)
Determine an atom or compound-term representation for the actual type of Stringy. It will be one of the atom var or one of the compound terms atom(L) or string(L), where L is the length of Stringy. This predicates behaves softly, i.e. preferentially fails on bad input.
 stringy_type_with_length(@Stringy, Type, Tuned)
As stringy_type_with_length/2, but setting Tuned to either true or throw will make the predicate throw on bad input.

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

 stringy_type(Arg1, Arg2, Arg3)