next up previous
Next: Form Handling in HTTP Up: Document: pillow_www6 Previous: Writing basic cgi-bin applications

LP/CLP Scripts for CGI Applications

CGI executables are often small- to medium-sized programs that do relatively simple tasks. This, added to the slow speed of the network connection in comparison with that of executing a program (which makes program execution speed less important) has made scripting languages (such as shell scripts or Perl) very popular for writing these scripts. The popularity is due to the fact that no compilation is necessary (extensive string handling capabilities also play an important role in the case of Perl), and thus changes and updates to the program imply only editing the source file.

Logic languages are, a priori, excellent candidates to be used as scripting languagesgif. However, the relative complication in making executables (needing in most systems to start the system, compile or consult the file, and make a saved state) and the often large size of the resulting executables may deter CGI application programmers. It appears convenient to provide a means for LP/CLP programs to be executable as scripts, even if with reduced performance.

It is generally relatively easy to support scripts with the same functionality in most LP/CLP systems (see [14] for an example developed for the CIAO system and adapted to SICStus). Let's assume that lpshell is a version of the LP/CLP system (for example, a saved state), which first loads the file given to it as the first argument (but excluding the first line and routing all loading messages away from the standard output) and then starts execution at main/1 (the argument provides the list of command line options). Then, for example, in a Unix system, the following program can be run directly as a script without any need for compilation:

#!/usr/local/bin/lpshell

main(_) :-
    write('Content-type: text/html'), nl, 
    write('<HTML>'),
    write('Hello world.'),
    write('</HTML>').



<herme@fi.upm.es>-< webmaster@clip.dia.fi.upm.es>
Last updated on Mon Mar 31 18:18:15 MET DST 1997