AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • SWI-Prolog extensions
        • The string type and its double quoted syntax
          • Predicates to support adapting code for double quoted strings
            • list_strings/0
            • string_predicate/1
            • valid_string_goal/1
    • Packages
Availability::- use_module(library(check)).(can be autoloaded)
Source[det]list_strings
[det]list_strings(+Options)
List strings that appear in clauses. This predicate is used to find portability issues for changing the Prolog flag double_quotes from codes to string, creating packed string objects. Warnings may be suppressed using the following multifile hooks:

  • string_predicate/1 to stop checking certain predicates
  • valid_string_goal/1 to tell the checker that a goal is safe.
See also
Prolog flag double_quotes.
Availability::- use_module(library(check)).(can be autoloaded)
Sourcelist_strings
This predicate may be used to assess compatibility issues due to the representation of double quoted text as string objects. See section 5.2 and section 5.2.3. To use it, load your program into Prolog and run list_strings/0. The predicate lists source locations of string objects encountered in the program that are not considered safe. Such string need to be examined manually, after which one of the actions below may be appropriate:

  • Rewrite the code. For example, change [X] = "a" into X = 0'a.
  • If a particular module relies heavily on representing strings as lists of character code, consider adding the following directive to the module. Note that this flag only applies to the module in which it appears.
              :- set_prolog_flag(double_quotes, codes).
              

  • Use a back quoted string (e.g., `text`). Note that this will not make your code run regardless of the --traditional command line option and code exploiting this mapping is also not portable to ISO compliant systems.
  • If the strings appear in facts and usage is safe, add a clause to the multifile predicate check:string_predicate/1 to silence list_strings/0 on all clauses of that predicate.
  • If the strings appear as an argument to a predicate that can handle string objects, add a clause to the multifile predicate check:valid_string_goal/1 to silence list_strings/0.