Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kamahen opened this issue Nov 1, 2024 · 2 comments
Open

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

kamahen opened this issue Nov 1, 2024 · 2 comments

Comments

@kamahen
Copy link
Member

kamahen commented Nov 1, 2024

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
$ 
@JanWielemaker
Copy link
Member

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.

@kamahen
Copy link
Member Author

kamahen commented Nov 3, 2024

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants