• 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.26 library(macros): Macro expansion
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
      • The SWI-Prolog library
        • library(macros): Macro expansion
          • Defining and using macros
          • Implementation details
          • Predicates
            • include_macros/3
            • expand_macros/5
            • macro_position/1
    • Packages

A.26.3 Predicates

[semidet]include_macros(+M, +Macro, -Expanded)
Include macros from another module. This predicate is a helper for #import(File). It calls’$macro’/2 in M, but fails silently in case Macro is not defined in M as it may be defined in another imported macro file or further down in the current file.
[semidet]expand_macros(+Module, +TermIn, -TermOut, +PosIn, -PosOut)
Perform macro expansion on TermIn with layout PosIn to produce TermOut with layout PosOut. The transformation is performed if the current load context module is Module (see prolog_load_context/2).

This predicate is not intended for direct usage.

[det]macro_position(-Position)
True when Position is the position of the macro. Position is a term File:Line:LinePos. If File is unknown it is unified with -. If Line and/or LinePos are unknown they are unified with 0. This predicate can be used in the body of a macro definition to provide the source location. The example below defines #pp(Var) to print a variable together with the variable name and source location.
#define(pp(Var), print_message(debug, dump_var(Pos, Name, Var))) :-
    (   var_property(Var, name(Name))
    ->  true
    ;   Name = 'Var'
    ),
    macro_position(Pos).

:- multifile prolog:message//1.
prolog:message(dump_var(Pos,Name,Var)) -->
    [ url(Pos), ': ',
      ansi([fg(magenta),bold], '~w', [Name]), ' = ',
      ansi(code, '~p', [Var])
    ].

ClioPatria (version V3.1.1-51-ga0b30a5)