trealla-prolog / trealla

A compact, efficient Prolog interpreter written in plain-old C.
MIT License
272 stars 13 forks source link

Relative Prolog text file not found #615

Closed Jean-Luc-Picard-2021 closed 5 days ago

Jean-Luc-Picard-2021 commented 1 week ago

Somehow either a file is silently not consulted, or a predicate doesn't become visible. Could be a backward compatibility problem form ISO modules to ISO core. Since non-modules should have all

predicates automatically exported? If I do in Trealla Prolog I get:

$ ./tpl -v
Trealla Prolog (c) Infradig 2020-2024, v2.59.1-22-g5aa60f

$ ./tpl
?- ['mod/foo.p'].
   true.

?- bar.
   throw(error(existence_error(procedure,bar/0),bar/0)).

If I do in SWI-Prolog I get:

$ swipl --version
SWI-Prolog version 9.0.4 for x86_64-linux

$ swipl

?- ['mod/foo.p'].
true.

?- bar.
hello
true.

The test case is relatively simple, a directory mod, with two files:

bar.p.log foo.p.log

Jean-Luc-Picard-2021 commented 1 week ago

LoL, its even worse in Scryer Prolog:

$ target/release/scryer-prolog -v
v0.9.4-201-gc39ea481

$ target/release/scryer-prolog
?- ['mod/foo.p'].
   error(domain_error(directive,todo_insert_invalid_term_here),load/1).
infradig commented 1 week ago

Trealla doesn't support random predicate calls as directives, like SWI-Prolog does.

infradig commented 1 week ago

I expect Scryer doesn't either.

Jean-Luc-Picard-2021 commented 1 week ago

Make [_|_] a directive, or else throw an error.

Now it is silent and hence very difficult to debug.

Especially when porting code that works in SWI-Prolog.

pmoura commented 1 week ago

Top-level shortcuts should never be used in source files. Throwing an error is the best and compliant option here.

Jean-Luc-Picard-2021 commented 5 days ago

Some error is thrown, but it has still a bug somewhere. Just compare Trealla Prolog with Scryer Prolog. Trealla Prolog does not lookup use_module/1 argument relative to

the parent file, or maybe its an file name extension problem?

~/trealla$ ./tpl
?- ['../shared/foo'].
Warning: module file not found: bar
   true.

Scryer Prolog can lookup use_module/1 argument correctly:

~/scryer-prolog$ target/release/scryer-prolog
?- ['../shared/foo'].
   true.

?- bar.
hello
   true.

The test cases are, placed it in a ~/shared folder:

bar.pl.log

bar :- write(hello), nl.

foo.pl.log

:- use_module('bar').

The bug is a little annoying, since I cannot share Prolog text files among two Prolog systems. Have always to copy the stuff or otherwise modify it to fix the bug.

Jean-Luc-Picard-2021 commented 5 days ago

Ok!

$ ./tpl -v
Trealla Prolog (c) Infradig 2020-2024, v2.59.5

~/trealla$ ./tpl
?- ['../shared/foo'].
   true.
?- bar.
hello
   true.