[R6RS] Naked scripts

Anton van Straaten anton at appsolutions.com
Tue Aug 8 11:51:09 EDT 2006


Here's a sketch of a proposal for naked scripts -- scripts which don't 
need to be explicitly wrapped in a library forms.  It's an extension of 
the existing proposal, so shouldn't interfere with that proposal's good 
properties.

Sorry for sending this so close to the conference call - however, I can 
describe the proposal quickly enough during the call, it's pretty 
straightforward.

Kent has proposed[*] that a script header should contain a <script spec> 
of the form (script <library name> <entry name>).  This specifies that a 
script contains an explicitly-defined library which contains a procedure 
<entry name> as the entry point for the script.

I propose adding a variation on this <script spec> which omits the 
<entry name>, i.e.:

   (script <library name>)

This specifies that the current compilation unit (?) is a script which 
contains interleaved toplevel definitions and expressions, outside of 
any explicit library definition.  These definitions and expressions are 
treated as the body of a library named <library name>, rewritten to 
conform to the requirements of a library body, e.g. written into a big 
letrec* with dummy definitions where necessary.  Interleaved syntax 
definitions also need to be supported.

In addition, naked scripts would automatically import a composite 
library such as "r6rs" or "r6rs-big".  This would allow many scripts to 
be written without requiring an explicit import statement.

Finally, we should consider making the #!r6rs declaration optional (if 
it isn't already).  If a user chooses to omit it, they're responsible 
for figuring out whether their script will run correctly with the script 
engine they're using.

These changes would enable scripts such as the following:

   #!/usr/bin/env scheme-script
   (script hello-world)
   (display "Hello world")

...as opposed to this, which conforms to my understanding of the 
existing proposal:

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

Some notes:

1. Naked scripts would need a (command-line) procedure or similar, to 
access command line arguments.  Mike pointed out that this makes it 
harder to control scripts externally, e.g. from a REPL.  However, this 
would be a choice made by the user - if they want an externally 
controllable script, they can define an explicit library with a named 
entry point.

2. Mike pointed out that the goal of interleaving definitions and 
expressions is orthogonal to the notion of a script, in the sense of a 
self-executing source program.  I agree with that, but I nevertheless 
think that the script is a natural place to implement such a feature in 
the current R6RS.  I'm open to factoring this differently, but I'm not 
sure that it's important to do so.

Anton

[*] https://r6rs.scheming.org/node/324#comment-1652




More information about the R6RS mailing list