Re: consult/1 at the top of a file
Paulo Moura <[email protected]> Thu, 22 Jul 2021 23:17:00 +0100
| Newsgroups | gmane.comp.gnu.prolog.general |
|---|---|
| Message-ID | <[email protected]> |
Hi Adam, > On 22 Jul 2021, at 22:51, Adam Russell <[email protected]> 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