Re: Nested conditional compilation

"Richard A. O'Keefe" <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 20/01/2014, at 12:16 AM, Steve Moyle wrote:

> Hi, is it possible to perform nested conditional compilation?

Did you _try_ it?

When I did in 6.5, seriously weird things happened.
Perhaps it works in later versions.

It can always be simulated:

:- if(G1).
   B1.
   :- if(G2).
      B12.
   :- else.
      B1_2.
   :- end.
:- else.
   B_1.
   :- if(G2).
      B_12.
   :- else.
      B_1_2.
   :- end.
:- end.

===>

:- if(G1).
   B1.
:- end.
:- if((G1, G2)).
   B12.
:- else.
   B1_2.
:- end.
:- if(\G1).
   B_1,
:- end.
:- if((\G1,G2)).
   B_12.
:- else.
   B_1_2.
:- end.

For the record, here's what 6.5.1 did.

% cat ab.pl
a :- true.

b :- fail.

<EOF>
% cat abc.pl
:- if(a).
   p(a). 
   :- if(b).
      p(a+b).
   :- else.
      p(a-b).
   :- end.   
:- else.  
   p(-a).
   :- if(b).
      p(-a+b).
   :- else.
      p(-a-b).
   :- end.   
:- end.   
<EOF>
% swipl
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 6.5.0)

?- [ab].
% ab compiled 0.00 sec, 3 clauses
true.

?- [abc].
ERROR: /home/cshome/o/ok/abc.pl:7:
        catch/3: Undefined procedure: end/0
Warning: /home/cshome/o/ok/abc.pl:7:
        Goal (directive) failed: user:end
ERROR: /home/cshome/o/ok/abc.pl:17:
        Unterminated conditional compilation from abc.pl:12
% abc compiled 0.01 sec, 1,316 clauses
true.

?- listing(p/1).
ERROR: [Thread 1]: exception handler failed to define listing/1

ERROR: [Thread 1]: exception handler failed to define listing/1

   Call: (6) listing(p/1) ? abort
% Execution Aborted
ERROR: load_files/2: No permission to load source `/opt/local/lib/swipl-6.5.0/library/prolog_history.pl' (Non-module file already loaded into module $toplevel; trying to load into prolog_history)
ERROR: setup_history/0: Undefined procedure: prolog_history:prolog_history/1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.