SDA SE Wiki

Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

User Tools

Site Tools


Prolog-Refactoring: Make Module

Core Transformation

Turning a file into a module mainly means adding the directive

:- module (moduleName, exportlist).

at the start of the file (see SWI-Prolog Manual for details).

Risks

Turning a Prolog file into a module has two implications that might change the program's semantics:

  1. the predicates not mentioned in the module's export list are

are visible outside only if accessed by explicit module qualification

  (that is, as "moduleName:goal" instead of just "goal".
- all metapredicates that access or manipulate prolog clauses
  (findall, setof, bagof, call, assert, retract, clause, ...)
  will by default act in the context of the module that calls them.
  That means, for instance, that clauses will be asserted in the new
  module and will not be automatically visible in the default module 
  "user", where they had "lived" before the refactoring. 

Analyses

In order to determine whether the above risks might actually occurr if the core transformation is performed, some analysis is necessary. In no particular order:

  • Which are the predicates called from outside the file?
    • → The export list must contain all of them (at least).
  • Which are the local predicates that call metapredicates?
    • → Their behaviour will change!
  • Which are the local predicates that are effectively user-defined metapredicates (that is, user-defined predicates that pass one of their parameters to a metapredicate).
    • → Calls of user-defined predicates must be treated like calls to system-defined predicates.

Corrective/Preventive Transformations

In order to avoid behavioural changes, some additional transformations are possible:

teaching/labs/xp/2009a/refactoring_to_modules.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2019