packages-cpp icon indicating copy to clipboard operation
packages-cpp copied to clipboard

swipl-ld ignores "-goal true" if there's no .pl file

Open kamahen opened this issue 1 year ago • 2 comments

In the following main.pl is an empty file. If it's specified, swipl-ld honours the -goal true and if it's not specified, I get the standard SWI-Prolog banner.

$ swipl-ld -goal true main.cpp main.pl && ./a.out  3.14 a b c ; echo $?
% Disabled autoloading (loaded 34 files)
% Disabled autoloading (loaded 7 files)
% Disabled autoloading (loaded 0 files)
% halt
[./a.out,3.14,a,b,c]
0
$ swipl-ld -goal true main.cpp && ./a.out  3.14 a b c ; echo $?
Welcome to SWI-Prolog (threaded, 64 bits, version 9.3.14-DIRTY)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

[./a.out,3.14,a,b,c]
0
$ cat main.cpp
#include "SWI-cpp2.h"
#include <iostream>

int
main(int argc, char *argv[])
{ PlEngine e(argv[0]);
  PlTermv av(1);
  PlTerm_tail l(av[0]);

  for(int i=0; i<argc; i++)
    PlCheckFail(l.append(PlTerm_string(argv[i])));
  PlCheckFail(l.close());

  PlQuery q("writeln", av);
  try
  { return q.next_solution() ? 0 : 1;
  } catch ( PlException &ex )
  { std::cerr << ex.what() << std::endl;
    return 1;
  }
}
$ cat main.pl
$ 

kamahen avatar Nov 01 '24 19:11 kamahen

With a Prolog file (be it empty), it creates a saved state that includes the Prolog flags. Without, it just uses the normal Prolog startup and as you do not pass the goal from your main.cpp to PlEngine, it is lost. The best I can see is to warn that these flags are no-ops if there is no Prolog code passed to swipl-ld.

JanWielemaker avatar Nov 02 '24 08:11 JanWielemaker

Documenting it seems a reasonable solution; but your answer also tells me that I don't understand how -goal and the arguments to PlEngine( work. I'll add this to my "documentation to-do list".

kamahen avatar Nov 03 '24 17:11 kamahen