Re: Warning: argument option processing changes

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 09/02/2013 09:04 AM, Boris Vassilev wrote:
> Hello,
>
> Is this section of the manual still correct:
>
> http://www.swi-prolog.org/pldoc/man?section=plscript
>
> In particular, is it still possible to have a file (hello.pl) like this:
>
> #!/path/to/swipl -q -t main -f
> main :- format('hello world~n'), halt.

That depends on the OS. Various Unix flavours have different ways for
processing the remainder of the line after the executable. Before,
SWI-Prolog tried to compensate for that by reading the file itself and
`fix' the command line arguments. This was very complicated and still
caused surprises. Now, it simply passes whatever the OS does as os_argv.
Next, it identifies the `application' arguments as `argv'.

> which can then be run with
> $ ./hello.pl
> (right now Prolog gives me back the help message when I try this)

Which means you have an OS that doesn't break the argument vector in the
first line.

> Reading the email above I understand that this shouldn't be used / is
> wrong, because of the multiple options passed. However, the email also
> talks about script files, starting with header #! line, but what is it
> for if I can drop the #! header altogether and run:
> $ swipl -q -t main -f hello.pl

Of course you can.  But I guess your users do not like this.  The
most portable way is simply

#!/path/to/swipl
<script>

and do all the rest using directives.  For example:

--- t.pl ---
#!/home/jan/bin/swipl

:- set_prolog_flag(verbose, silent).

:- initialization main.

main :-
	current_prolog_flag(argv, Argv),
	format('Called with ~q~n', [Argv]),
	halt.
--- end of t.pl ---

% ./t.pl hello world
Called with [hello,world]

	Cheers --- Jan

P.s.	Currently, the script must have extension .pl.  That must be
	fixed.

>
> Thank you,
> Boris
>
>
> On Mon, Aug 19, 2013 at 10:49 PM, Jan Wielemaker <[email protected]> wrote:
>> Hi,
>>
>> Prolog can be started in many ways and the new stuff around Carlo's
>> console and the Mac makes it even more complicated.  I spent most of
>> the day sorting out command line processing.  Pushed the changed,
>> which introduces some INCOMPATIBLE changes.  It does improve
>> compatibility with some other systems though.  Outline:
>>
>>  - The Prolog flag =argv= now only provides `user arguments'.  I.e.,
>>    arguments processed by Prolog are not there.  This is compatible
>>    with at least YAP and SICStus.   All arguments are still available
>>    with the new flag =os_argv=.
>>
>>  - I removed all stuff trying to be clever with arguments from #!
>>    scripts.  Most of this didn't work anyway, leading to all sorts
>>    of hard to debug platform dependent surprises.  This concretely
>>    means that options in #! under Windows have no meaning.  On
>>    Unix systems, only #!/path-to-executable [option] (using only
>>    one option) is (AFAIK) fully portable.
>>
>>    Anything that can be handled using options can be handled with
>>    directives these days, so functionality-wise nothing changes.
>>
>>  - swipl [option ...] prolog-file ... loads the given Prolog files
>>    (extensions .pl and .qlf; this is processed *before* ~/.plrc).
>>
>>  - swipl [option ...] script-file arg ... processes script-file and
>>    passes the remaining options in the flag argv.  A script file
>>    is a file with any extension that starts with #!
>>
>> Updated all packages.  Also updated ClioPatria to deal with this.
>>
>> Sorry for the inconvenience.  Notably the change of the =argv=
>> flag will force changing some programs.  I think this was
>> unavoidable, considering established practice.
>>
>> If you see opportunities to further simplify things or reduce
>> compatibility impact, let me know.
>>
>>         Cheers --- Jan
>> _______________________________________________
>> 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.