Re: maybe a bug with prolog script

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 12/11/2013 12:30 AM, db wrote:
> Hello,
>
> The following prolog script
>
> -------------------------------
> #! /usr/bin/swipl  -t main -s
>
> main :-
>          catch(goal, E, (print_message(error, E), fail)),
>          halt.
> main :-
>          halt(1).
>
> goal :-
>          writeln('hello').
> ------------------------------
>
> works with SWI-Prolog version 6.4.1 for x86_64-linux
>
> does not work with SWI-Prolog version 6.6.0 for amd64,
> it displays :
>
> swipl: Usage:
>      1) swipl --help     Display this message (also -h)
>      2) swipl --version  Display version information (also -v)
>      3) swipl --arch     Display architecture
>      ...
>
> If I add arguments it works with SWI-Prolog version 6.4.1 for x86_64-linux
> and does not with  SWI-Prolog version 6.6.0 for amd64.
>
> Why ?

Unix(-like) systems vary in how they handle text after the
#!/path/to/exe. The old system tried to compensate for that my checking
the first line, re-reading it and re-interpreting it in a consistent
manner. This is hard to do in a compatible way and unexpectely forces
interpretation of the flags when calling "swipl -s script" because you
do not know whether "swipl -s script" was called or ./script. Anyway, in
the past this was needed because the stack options needed to be
processed before Prolog was started. Now we can set everything using
directives.

Systems do pass the options consistently (AFAIK) if there is a single
argument.  This allows for --traditional for V7 users who like to stick
with the old mode :-)

Typically you do something like this:

#!/usr/bin/swipl

:- set_prolog_flag(verbose, silent).
:- initialization main.

main :-
	current_prolog_flag(argv, Argv),
	<process>.

Note that this change also changes the argv flag to return the `user'
command line options rather than all of them unfiltered.  This is
easier and compatible to e.g., SICStus and YAP.

	Cheers --- Jan

>
> I have the same problem with the swi prolog version 6.5.3
>
> Thanks a lot for yours answers
>
> Dominique
> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.