Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel-eecis!gatech!news.mathworks.com!newsfeed.internetmci.com!in3.uu.net!EU.net!sun4nl!freya.let.rug.nl!vannoord
From: vannoord@let.rug.nl (Gertjan van Noord)
Subject: prolog source file executed as a script
Sender: news@let.rug.nl (News system at let.rug.nl)
Message-ID: <1996Aug23.080230.5177@let.rug.nl>
Date: Fri, 23 Aug 1996 08:02:30 GMT
Nntp-Posting-Host: saga.let.rug.nl
Organization: Faculteit der Letteren, Rijksuniversiteit Groningen, NL
Lines: 39

A while ago someone presented a tool called `prolog_shell' which could
be used to turn a prolog source file into a script (to be called from
the command line, or e.g. as a htbin script in a WWW application).

It seems there is an easier solution available which 
- does not require a specially constructed saved-state
- is more robust (prolog_shell requires exactly 2 lines of shell code
  followed by prolog code), and more general (you could even have several 
  incarnations of prolog in one script).

Here is an example:

#!/bin/sh
echo "<H2> Title </H2>
eval `/sysadm/web/htbin/cgiparse -form`
echo "Arguments: $FORM_a1<P>"
cat << EOF | /usr/local/bin/sicstus -f -a $FORM_a1

reconsult(user).

% begin of prolog source file; this includes a definition for
% the predicate main/1. Its single argument is a list of input
% arguments.

...
...
...

% change this for sicstus 3 (prolog_flag(argv,...)
:- unix(argv(Args)), main(Args).

EOF
# the EOF marks the end of the input to the sicstus command
# you can continue your shell script here...

-- 
dr Gertjan van Noord Alfa-informatica, RUG, Postbus 716, 9700 AS Groningen
vannoord@let.rug.nl      tel. +31-50-3635935      fax  +31-50-3636855
http://www.let.rug.nl/~vannoord/
