Re: Nested conditional compilation
Paulo Moura <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 20/01/2014, at 01:52, Richard A. O'Keefe <[email protected]> wrote: > > 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. You want ":- endif.", not ":- 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 Fixing the "end" -> "endif" typo: $ swipl % /Users/pmoura/.plrc compiled 0.00 sec, 2 clauses Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.1.5-3-g73a511b-DIRTY) Copyright (c) 1990-2013 University of Amsterdam, VU Amsterdam SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. Please visit http://www.swi-prolog.org for details. For help, use ?- help(Topic). or ?- apropos(Word). ?- [ab]. % ab compiled 0.00 sec, 3 clauses true. ?- [abc]. % abc compiled 0.00 sec, 9 clauses true. ?- listing(p/1). p(a). p(a-b). true. Cheers, Paulo ----------------------------------------------------------------- Paulo Moura Logtalk developer Email: <mailto:[email protected]> Web: <http://logtalk.org/> -----------------------------------------------------------------