Re: PrologScript with SWI 6.5.2

Boris Vassilev <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <CAFw8osJ+6jXJZftqNz=GDKWPCdhnZZ0ignYaXCBHs6X4BiPZZg@mail.gmail.com>
Hello Steve,

Guessing that you have the same issue as I did, here is Jan's response
(this happened on this list some three months ago):

>>>

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


On Wed, Dec 4, 2013 at 12:49 AM, Steve Prior <[email protected]> wrote:

> I'm trying to move PrologScript code from SWI 6.4.1 to 6.5.2 and though
> I've seen in the changelog that command line handling has changed I'm
> having trouble figuring out what changes to make.  The following code seems
> to do exactly what the current documentation from the SWI website does, but
> it doesn't work:
>
> sprior@ubuntu:~/plindexer$ cat foo
> #!/home/sprior/bin/swipl -q -t main -f
>
> main :-
>         write('hello there\n'),
>         halt.
> sprior@ubuntu:~/plindexer$ ./foo
> produces a SWI Prolog usage message.
>
>
> Can someone clue me in?
>
> Steve
> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>
-------------- next part --------------
HTML attachment scrubbed and removed
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.