• Places
    • Home
    • Graphs
    • Prefixes
  • Admin
    • Users
    • Settings
    • Plugins
    • Statistics
  • CPACK
    • Home
    • List packs
    • Submit pack
  • Repository
    • Load local file
    • Load from HTTP
    • Load from library
    • Remove triples
    • Clear repository
  • Query
    • YASGUI SPARQL Editor
    • Simple Form
    • SWISH Prolog shell
  • Help
    • Documentation
    • Tutorial
    • Roadmap
    • HTTP Services
  • Login

A.38.3.2 Reflective access to options
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
      • The SWI-Prolog library
        • library(predicate_options): Declare option-processing of predicates
          • Improving on the current situation
            • Reflective access to options
              • predicate_options/3
              • assert_predicate_options/4
              • current_predicate_option/3
              • check_predicate_option/3
              • current_option_arg/2
              • current_predicate_options/3
              • check_predicate_options/0
              • derive_predicate_options/0
              • retractall_predicate_options/0
              • derived_predicate_options/3
              • derived_predicate_options/1
    • Packages
Availability::- use_module(library(predicate_options)).(can be autoloaded)
Source[det]predicate_options(:PI, +Arg, +Options)
Declare that the predicate PI processes options on Arg. Options is a list of options processed. Each element is one of:

  • Option(ModeAndType) PI processes Option. The option-value must comply to ModeAndType. Mode is one of + or - and Type is a type as accepted by must_be/2.
  • pass_to(:PI,Arg) The option-list is passed to the indicated predicate.

Below is an example that processes the option header(boolean) and passes all options to open/4:

:- predicate_options(write_xml_file/3, 3,
                     [ header(boolean),
                       pass_to(open/4, 4)
                     ]).

write_xml_file(File, XMLTerm, Options) :-
    open(File, write, Out, Options),
    (   option(header(true), Options, true)
    ->  write_xml_header(Out)
    ;   true
    ),
    ...

This predicate may only be used as a directive and is processed by expand_term/2. Option processing can be specified at runtime using assert_predicate_options/3, which is intended to support program analysis.

ClioPatria (version V3.1.1-51-ga0b30a5)