Changeset 4206 for trunk/manuals/userman/running.html
- Timestamp:
- 04/12/08 14:14:06 (8 months ago)
- Files:
-
- 1 modified
-
trunk/manuals/userman/running.html (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/manuals/userman/running.html
r3944 r4206 182 182 <dl> 183 183 <dt><code>hook(Object)</code></dt> 184 <dd>Allows the definition of a compiler hooks that are called for each term read form a source file and for each compiled goal. This option specifies bothan object (which can be the pseudo-object <code>user</code>) implementing the <code>expanding</code> built-in protocol. The object is expected to define clauses for the <a title="Consult reference manual" href="../refman/methods/term_expansion2.html"><code>term_expansion/2</code></a> and <a title="Consult reference manual" href="../refman/methods/goal_expansion2.html"><code>goal_expansion/2</code></a> predicates. In the case of the <code>term_expansion/2</code> predicate, the first argument is the term read form the source file while the second argument returns a list of terms corresponding to the expansion of the first argument. In the case of the <code>goal_expansion/2</code> predicate, the second argument should be a goal resulting from the expansion of the goal in the first argument. The predicate <code>goal_expansion/2</code> is called on the expanded goals so care must be taken to avoid compilation loops.</dd>184 <dd>Allows the definition of a compiler hooks that are called for each term read form a source file and for each compiled goal. This option specifies an object (which can be the pseudo-object <code>user</code>) implementing the <code>expanding</code> built-in protocol. The object is expected to define clauses for the <a title="Consult reference manual" href="../refman/methods/term_expansion2.html"><code>term_expansion/2</code></a> and <a title="Consult reference manual" href="../refman/methods/goal_expansion2.html"><code>goal_expansion/2</code></a> predicates. In the case of the <code>term_expansion/2</code> predicate, the first argument is the term read form the source file while the second argument returns a list of terms corresponding to the expansion of the first argument. In the case of the <code>goal_expansion/2</code> predicate, the second argument should be a goal resulting from the expansion of the goal in the first argument. The predicate <code>goal_expansion/2</code> is called on the expanded goals so care must be taken to avoid compilation loops.</dd> 185 185 </dl> 186 186 <dl> … … 490 490 </p> 491 491 492 <h3 id="running_hooks">Using compilation hooks and term expansion for debugging</h3> 493 494 <p> 495 It is possible to use compilation hooks and the term expansion mechanism for conditional compilation of debugging goals. Assume that we chose the predicate <code>debug/1</code> to represent debug goals. For example: 496 </p> 497 <pre>append([], List, List) :- 498 debug((write('Base case: '), writeq(append([], List, List)), nl)). 499 append([Head| Tail], List, [Head| Tail2]) :- 500 debug((write('Recursive case: '), writeq(append(Tail, List, Tail2)), nl)), 501 append(Tail, List, Tail2).</pre> 502 <p> 503 When debugging, we want to call the argument of the predicate <code>debug/1</code>. This can be easily accomplished by defining a hook object containing the following definition for <code>goal_expansion/2</code>: 504 </p> 505 <pre>goal_expansion(debug(Goal), Goal).</pre> 506 <p> 507 When not debugging, we can use a second hook object to discard the <code>debug/1</code> calls by defining the predicate <code>goal_expansion/2</code> as follows: 508 </p> 509 <pre>goal_expansion(debug(_), true).</pre> 510 <p> 511 The Logtalk compiler automatically removes any redundant calls to the built-in predicate <code>true/0</code> when compiling object predicates. 512 </p> 513 492 514 <div class="footer"> 493 515 <div class="copyright"> 494 516 <span>Copyright © <a href="mailto:pmoura@logtalk.org">Paulo Moura</a> — <a href="http://logtalk.org">Logtalk.org</a></span><br/> 495 <span>Last updated on: December 3, 2007</span>517 <span>Last updated on: April 9, 2008</span> 496 518 </div> 497 519 <div class="navbottom">
