users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: consult/1 at the top of a file


From: Paulo Moura
Subject: Re: consult/1 at the top of a file
Date: Thu, 22 Jul 2021 23:17:00 +0100

Hi Adam,

> On 22 Jul 2021, at 22:51, Adam Russell <ac.russell@live.com> wrote:
> 
> This is such a small thing, but I had never noticed this before.
> 
> In other Prologs it is possible to add a line such as
> 
> :-['some_file.p'].

This is a really bad practice. Top-level shortcuts (for consulting a file) 
should only used at the top-level. Moreover, using arbitrary goals as 
directives requires in practice that they be called as soon as found. But these 
goals often have side-effects that usually are not undone if there's a problem 
later in the file (e.g. a syntax error or another arbitrary goal used as a 
directive that fails). In this case, a restart is the only safe bet as simply 
reloading a fixed file may easily result in duplicated side-effects.

> at the top of a file and the file is consulted in the usual way. But it seems 
> Gnu Prolog does not allow this? 

Which is a good thing.

> When I try I get
>    "Unknown directive '.'/2 - maybe use initialization/1 - directive ignored"
> 
> If I then do as suggested with
> 
> :-initialization(['some_file.p']).
> 
> it works as expected.
> 
> Since initialization/1 is an ISO directive I wonder, is this a more preferred 
> way of doing this? And the other way is discouraged to the point where GNU 
> Prolog does not even support it?

:- initialization(consult(...)).

Cheers,
Paulo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]