compilability of scripts Marc Feeley (10 Mar 2001 17:33 UTC)
Re: compilability of scripts sperber@xxxxxx (20 Mar 2001 10:55 UTC)
Re: compilability of scripts Marc Feeley (20 Mar 2001 12:43 UTC)

compilability of scripts Marc Feeley 10 Mar 2001 17:33 UTC

I would like scripts to be compilable on Scheme systems that offer a
compiler of some sort.  This would allow the development of the script
to be done with an interpreter and when speed is needed it can be
compiled.

Say we have a script "S.scm" that is invoked with the command

        S.scm arg1 arg2 arg3

Compiling this script can be done using one of these approaches:

1) Use the compiler to generate an executable, say "S.exe", that can
   be invoked directly as:

        S.exe arg1 arg2 arg3

   This requires launching the compiled script differently than the
   noncompiled script, which is unfortunate.  There is also the
   problem (for the compiler) of sending the command-line arguments to
   the right function.  Conceivably the compiler could parse the
   invocation of "scheme-script" in the script, but for this to be
   practical the syntax of the shell part of the script should be a well
   defined subset of the shell syntax, for example always of the form:

        exec scheme-script "$0" --call <identifier> "$@"

   Alternatively, the shell part of the script could be free-form
   except that the first occurrence of "--call <identifier>" defines
   the function to call, and it is assumed that "scheme-script"
   receives all of the script arguments.  This would allow
   Windows scripts to use the Windows syntax:

        scheme-script %0 --call <identifier> %*

2) Use the compiler to generate a "FASL file" (a compiled
   representation of "S.scm" that can be loaded quickly), say
   "S.fasl".  This can be a bytecode file, a binary file, heap image,
   etc.  Scheme implementations which can generate FASL files
   typically allow loading the file with (load "S.fasl") or a command
   line option.  Note that it is possible to define "scheme-script" so
   that when

        S.scm arg1 arg2 arg3

   calls "scheme-script S.scm ...", it will load the file "S.fasl"
   instead of "S.scm" if "S.fasl" exists.  For this to work and be
   portable, SRFI 22 would have to define the filename extension of
   FASL files, or specify that an implementation dependent search is
   performed for a file to load with the same base name (i.e. "S").

   Alternatively, this search for the file to load could be done by
   "scheme-script" only if the script file argument has no extension
   (under UNIX you can only invoke a script with the same extension as
   its filename, but under Windows, scripts must have the extension
   ".BAT" or ".CMD" and can be invoked with or without the extension).
   So, a script "S.scm" will always load "S.scm", but a script "S" may
   load "S.fasl", "S.foobar", "S.bat", "S", etc.

Could something like this be added to SRFI 22?

Marc