SDA SE Wiki

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

User Tools

Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
teaching:labs:xp:2009a:refactoring_to_modules [2009/03/15 23:31]
Günter Kniesel created
teaching:labs:xp:2009a:refactoring_to_modules [2018/05/09 01:59] (current)
Line 1: Line 1:
 +====== Prolog-Refactoring:​ Make Module ======
 +
 +===== Core Transformation =====
 +
 +Turning a file into a module mainly means adding the directive
 +<Code lang-prolog>​
 +:- module (moduleName,​ exportlist).
 +</​Code>​
 +at the start of the file (see [[http://​gollem.science.uva.nl/​SWI-Prolog/​Manual/​usingmodules.html|SWI-Prolog Manual]] for details).
 +
 +===== Risks =====
 +
 +Turning a Prolog file into a module has two implications that might change the program'​s semantics:
 +  - 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