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

5.3 Syntax changes
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • SWI-Prolog extensions
        • Syntax changes
          • Operators and quoted atoms
          • Compound terms with zero arguments
          • Block operators
    • Packages

5.3.2 Compound terms with zero arguments

As of SWI-Prolog version 7, the system supports compound terms that have no arguments. This implies that e.g., name() is valid syntax. This extension aims at functions on dicts (see section 5.4) as well as the implementation of domain specific languages (DSLs). To minimise the consequences, the classic predicates functor/3 and =../2 have not been modified. The predicates compound_name_arity/3 and compound_name_arguments/3 have been added. These predicates operate only on compound terms and behave consistently for compounds with zero arguments. Code that generalises a term using the sequence below should generally be changed to use compound_name_arity/3.

    ...,
    functor(Specific, Name, Arity),
    functor(General, Name, Arity),
    ...,

Replacement of =../2 by compound_name_arguments/3 is typically needed to deal with code that follow the skeleton below.

    ...,
    Term0 =.. [Name|Args0],
    maplist(convert, Args0, Args),
    Term =.. [Name|Args],
    ...,

For predicates, goals and arithmetic functions (evaluable terms), <name> and <name>() are equivalent. Below are some examples that illustrate this behaviour.

go() :- format('Hello world~n').

?- go().
Hello world

?- go.
Hello world

?- Pi is pi().
Pi = 3.141592653589793.

?- Pi is pi.
Pi = 3.141592653589793.

Note that the cannonical representation of predicate heads and functions without arguments is an atom. Thus, clause(go(), Body) returns the clauses for go/0, but clause(-Head, -Body, +Ref) unifies Head with an atom if the clause specified by Ref is part of a predicate with zero arguments.

ClioPatria (version V3.1.1-51-ga0b30a5)