Damn! I only recently learned about predicate indicators from Daniel and I 
guess it’s not ingrained enough yet.
I did what you posted and it works!

My “./tests/runalltests” script works once again as does my up-one-level and I 
learned some more to boot!

You are never too old to learn and I never stop!

In precisely 1 hour and 12 minutes UK time I shall be 48 years old, so that’s 
29 years in the business and 37 years since I learned BASIC in school and I am 
still hooked on “what is computing”.

Good night everybody and thanks again Paulo, finally you told me something I 
understood! ;)

Cheers,
Sean.


On 9 Nov 2013, at 22:38, Paulo Moura <[email protected]> wrote:

> 
> On 09/11/2013, at 22:30, Sean Charles <[email protected]> wrote:
> 
>> I am having troubles with files being included more than once and I don’t 
>> seem to be able to code my away around it!
>> 
>> In my utils.pl file I have a predicate called now_string() and I have 
>> application code and test scripts that use it and now, after refactoring, my 
>> test scripts break because none of the files under test are pulling it in… I 
>> removed it from one file because that file was being included in another 
>> file yadda yadda yadaa you know how these things get from time to time.
>> 
>> I thought I could put in a test like this:
>> 
>> :-if( \+ current_predicate(utils_included)).
>> :-include('utils.pl').
>> :-endif.
>> 
>> But it won’t play ball. In the utils.pl file the first fact is 
>> “utils_included.” I hope you get the picture, problem is, gprolog doesn’t!
>> 
>> compiling /Users/seancharles/Documents/FELT/felt-prolog/feltlexer.pl for 
>> byte code...
>> /Users/seancharles/Documents/FELT/felt-prolog/feltlexer.pl:38:1: syntax 
>> error: . or operator expected after expression
>> /Users/seancharles/Documents/FELT/felt-prolog/feltlexer.pl:39: fatal error: 
>> unexpected endif directive
>> 
>> Is there an “accepted technique” for handling file included in Prolog 
>> applications to avoid multiple definitions and things?
> 
> Try:
> 
> :- if(\+ current_predicate(utils_included/0)).
> :- initialization(consult('utils.pl')).
> :- endif.
> 
> The initialization/1 is deferred until the file is loaded so you shouldn't 
> get an error related to a missing endif/0 directive that, I assumed is that 
> to some implementation issue with the include/1 directive. Also note that 
> current_predicate/1 takes (or returns) a predicate indicator as argument, not 
> a predicate functor.
> 
> Cheers,
> 
> Paulo
> 
> -----------------------------------------------------------------
> Paulo Moura
> Logtalk developer
> 
> Email: <mailto:[email protected]>
> Web:   <http://logtalk.org/>
> -----------------------------------------------------------------
> 
> 
> 
> 
> 
> _______________________________________________
> Users-prolog mailing list
> [email protected]
> https://lists.gnu.org/mailman/listinfo/users-prolog

_______________________________________________
Users-prolog mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/users-prolog

Reply via email to