PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 25, 2022

[FIXED] How to list the clauses inside a module in SWI-Prolog?

 August 25, 2022     module, prolog, reflection, swi-prolog     No comments   

Issue

SWI-Prolog has for example the library(dcgbasics) for use with DCGs.

While referencing the module is easy with use_module/1, e.g.

:- use_module(library(dcg/basics)).

trying to use listing/1 with it is not so easy.

?- listing(dcg:_).
true.

?- listing(dcgbasics:_).
true.

?- basics:listing.
true.

What is the correct way to get a listing of the clauses in library(dcg/basics)?


Follow up after answer given.

To list a specific clause, e.g. blanks//0 the query is

?- listing(dcg_basics:blanks).
blanks(A, B) :-
    blank(A, C),
    !,
    D=C,
    blanks(D, B).
blanks(A, A).

true.

Solution

Use either:

?- dcg_basics:listing.

Or:

?- listing(dcg_basics:_).

The first argument of use_module/1-2 is a file specification, not a module name. But listing the module contents requires the actual module name, which may be different (as it is the case here) from the module file basename. But how to find the module name from the file specification? In the particular case of SWI-Prolog:

?- absolute_file_name(library(dcg/basics), Path, [extensions([pl])]),
   module_property(Module, file(Path)).
Path = '/Users/pmoura/lib/swipl/library/dcg/basics.pl',
Module = dcg_basics.


Answered By - Paulo Moura
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing