@@ -844,16 +844,14 @@ vs.\ Windows).
844
844
\subsubsection{Using PrologScript} \label{sec:plscript}
845
845
846
846
A Prolog source file can be used directly as a Unix program using the
847
- Unix \verb$#!$ magic start. The same mechanism is useful for specifying
848
- additional parameters for running a Prolog file on Windows. The Unix
849
- \verb$#!$ magic is allowed because if the first letter of a Prolog file
850
- is \verb$#$, the first line is treated as a comment.\footnote{The
851
- \texttt{\#}-sign can be the legal start of a normal Prolog clause. In
852
- the unlikely case this is required, leave the first line blank or add a
853
- header comment.} To create a Prolog script, use one of the two
854
- alternatives below as first line. The first can be used to bind a script
855
- to a specific Prolog installation, while the latter uses the default
856
- prolog installed in \verb"$PATH".
847
+ Unix \verb$#!$ magic start. The Unix \verb$#!$ magic is allowed because
848
+ if the first letter of a Prolog file is \verb$#$, the first line is
849
+ treated as a comment.\footnote{The \texttt{\#}-sign can be the legal
850
+ start of a normal Prolog clause. In the unlikely case this is required,
851
+ leave the first line blank or add a header comment.} To create a Prolog
852
+ script, use one of the two alternatives below as first line. The first
853
+ can be used to bind a script to a specific Prolog installation, while
854
+ the latter uses the default prolog installed in \verb"$PATH".
857
855
858
856
\begin{code}
859
857
!/path/to/swipl
@@ -866,26 +864,25 @@ portability, the \verb$#!$ must be followed immediately with an absolute
866
864
path to the executable and should have none or one argument. Neither the
867
865
executable path, nor the argument shall use quotes or spaces. When
868
866
started this way, the Prolog flag \prologflag{argv} contains the command
869
- line arguments that follow the script invocation. Below is a simple
870
- script doing expression evaluation:
867
+ line arguments that follow the script invocation.
868
+
869
+ Starting with version 7.5.8, initialization/2 support the \arg{When}
870
+ options \const{program} and \const{main}, allowing for the following
871
+ definition of a Prolog script that evaluates an arithmetic expression on
872
+ the command line. Note that main/0 is defined lib the library
873
+ \pllib{main}. It calls main/1 with the command line arguments after
874
+ disabling signal handling.
871
875
872
876
\begin{code}
873
877
#!/usr/bin/env swipl
874
878
875
- :- initialization main.
879
+ :- initialization(main, main) .
876
880
877
- eval :-
878
- current_prolog_flag(argv, Argv),
881
+ main(Argv) :-
879
882
concat_atom(Argv, ' ', SingleArg),
880
883
term_to_atom(Term, SingleArg),
881
884
Val is Term,
882
885
format('~w~n', [Val]).
883
-
884
- main :-
885
- catch(eval, E, (print_message(error, E), fail)),
886
- halt.
887
- main :-
888
- halt(1).
889
886
\end{code}
890
887
891
888
And here are two example runs:
@@ -895,7 +892,6 @@ And here are two example runs:
895
892
3
896
893
% ./eval foo
897
894
ERROR: is/2: Arithmetic: `foo/0' is not a function
898
- %
899
895
\end{code}
900
896
901
897
The Windows version simply ignores the \verb$#!$ line.\footnote{Older
0 commit comments