Next: , Previous: , Up: Compiling   [Contents][Index]


6.5.4 Compiling to a standalone application

A Java application is a Java class with a special method (whose name is main). The application can be invoked directly by naming it in the Java command. If you want to generate an application from a Scheme program, create a Scheme source file with the definitions you need, plus the top-level actions that you want the application to execute.

For example, assuming your Scheme file is MyProgram.scm, you have two ways at your disposal to compile this Scheme program to a standalone application:

  1. Compile in the regular way described in the previous section, but add the --main option.
    kawa --main -C MyProgram.scm
    

    The --main option will compile all Scheme programs received in arguments to standalone applications.

  2. Compile in the regular way decribed in the previous section, but add the main: #t module compile option to your module.
    ;; MyProgram.scm
    (module-name <myprogram>)
    (module-compile-options main: #t)
    
    kawa -C MyProgram.scm
    

    This way you can compile multiple Scheme programs at once, and still control which one(s) will compile to standalone application(s).

Both methods will create a MyProgram.class which you can either load (as described in the previous section), or invoke as an application:

java MyProgram [args]

Your Scheme program can access the command-line arguments args by using the global variable ‘command-line-arguments’, or the R6RS function ‘command-line’.

If there is no explicit module-export in a module compiled with --main then no names are exported. (The default otherwise is for all names to be exported.)


Next: , Previous: , Up: Compiling   [Contents][Index]