Ticket #6 (closed enhancement: wontfix)

Opened 6 months ago

Last modified 6 months ago

Add support for conditional compilation of predicates

Reported by: victor Owned by: pmoura
Priority: minor Milestone: Logtalk enhancements
Component: compiler Version: 2.31.4
Keywords: Cc:

Description

Hi,

There is an example to explain the idea since it is difficult to express it with words :

Let imagine a special predicate named conditional_compilation/2. The first argumentation would be a tagname and the second would be predicates.

For example we can write :

my_pred(X) :-
  conditional_compilation(debug, (write('Debug message'))),
  conditional_compilation(info, (write('Info message'))),
  another_pred(X).

There would be a compilation flag, for example named, conditionnal_tag/1, that would tell to the compiler which tagged conditional_compilation predicate should be enabled. For example if we compile the example with conditionnal_tag(debug) as a compilation flag, the previous example would be equivalent to this :

my_pred(X) :-
  write('Debug message'),
  another_pred(X).

If debug AND info are enabled it will look like :

my_pred(X) :-
  write('Debug message'),
  write('Info message'),
  another_pred(X).

These example are for debugging message, but I am sure there is a lot of another uses.

Attachments

Change History

Changed 6 months ago by pmoura

  • status changed from new to assigned
  • owner set to pmoura

Changed 6 months ago by pmoura

I wonder if it's worth to add the described functionality as a hard-coded built-in feature. You can already accomplish this functionality by using the compiler option hook/1 together with appropriated definitions for the user-defined goal_expansion/2 predicate. Basically, you define two hook objects. The first hook object will convert debug calls to the goal "true" and will be used for production runs. The second hook object would be used for debugging and will convert debug calls into their argument. After defining the two hook objects, is just a question of writing two loader files, each one using its hook/1 compiler option.

Changed 6 months ago by victor

Hello,

It works like a charm,

I made two object implementing expanding, one that replace debug(A) by A and one that replace debug(_) by true.

I can even put debug specific predicates in the first object, and use uses/2 to import them.

Do we need to change the statut to wontfix ?

Changed 6 months ago by pmoura

  • status changed from assigned to closed
  • resolution set to wontfix

Glad you got the sketched alternative working as you intended. I'm changing the ticket status to "wontfix" for now and adding a new example to the Logtalk distribution illustrating this debugging solution.

Add/Change #6 (Add support for conditional compilation of predicates)

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.