[R6RS] Naked scripts

Anton van Straaten anton at appsolutions.com
Thu Aug 10 16:13:13 EDT 2006

I'm still working on a note about the script issues, which I expect to 
post later today.  But while working on it, something occurred to me.

Kent wrote:
> So I propose this instead:
>   #!/usr/bin/scheme-script <line break> <optional #!r6rs>
>   (import <import-spec>*)
>   <library body>
> with a nullary procedure command-line that returns the command-line, with
> the name of the script first followed by the arguments as strings.

I'm not sure if this might have been intended, but if the above were 
extended by allowing the library body to be followed by zero or more 
libraries, i.e. (with square brackets indicating optional bits):

   #!/usr/bin/[env ]scheme-script <line break> [#!r6rs]
   (import <import-spec>*)
   <library body>

...then I think it would support the kind of rigor Mike is interested 
in, by allowing a script to both define and explicitly invoke a library, 

   #!/usr/bin/env scheme-script
   (import r6rs hello)
   (main (command-line))
   (library hello
      (import r6rs)
      (export main)
      (define (main args)
        (display "Hello world!")))

This actually looks almost identical to the earlier proposal summarized 
at https://r6rs.scheming.org/node/324#comment-1652 , with the 
superficial difference being that in the above example, this:

   (import r6rs hello)
   (main (command-line))

has replaced this:

   (script hello main)

This change would allow top-level code in scripts, but also allows 
scripts to be implemented as libraries to support testing, debugging, 
and reuse in other contexts.

It would not be essential to specify any facilities for naming or 
importing the top-level code in such a script, since if you want that 
ability, you would implement the script as a library, and import that 
library.  However, someone just wanting to write a simple script, 
without worrying about test harnesses and reuse, could write something 
as simple as:

   (import r6rs)
   (display "hello world")


More information about the R6RS mailing list