Getting Started with NexJ Scheme

To run the REPL interactively, first build the JAR file and then invoke it:

   C:\> ant nexj-scheme.jar
   C:\> java -jar nexj-scheme.jar

Available ant tasks:

nexj-scheme.jar
compile the Java files and bundle the object and source files into the JAR file
doc
generate Javadoc from the codebase
clean
remove all of the files generated by the ant tasks

Running the NexJ Scheme Interpreter

You start the interpreter from a console by executing the java -jar command. Once running, you interact with the NexJ Scheme interpreter simply by typing Scheme expressions:

   C:\> java -jar nexj-scheme.jar 
   Feb 1, 2011 2:13:21 AM nexj.core.util.log.j2se.J2SELogger log
   INFO: Using system configuration properties
   ; NexJ Scheme
   
   > (+ 2 5)
   ; 7
   
   > "hello world!"
   ; "hello world!"
   
   > (define msg "hello world!")
   ; "hello world!"
   
   > msg
   ; "hello world!"
   
   > (string-length msg)
   ; 12
   
   > (* (string-length msg) 2)
   ; 24

Using Scheme Libraries

You can load a file of Scheme commands using the load function. Say for example you have a file named utils.scm containing:

   (import 'java.lang.System)
   (define (addemup a b) (+ a b))
   (define exit (lambda () (java.lang.System'exit 0)))

Then you can use the functions addemup and exit with:

   C:\> java -jar nexj-scheme.jar 
   Feb 1, 2011 2:15:09 AM nexj.core.util.log.j2se.J2SELogger log
   INFO: Using system configuration properties
   ; NexJ Scheme
   
   > (load "utils.scm")
   ; ()
   
   > (addemup 3 4)
   ; 7
   
   > (exit)
   
   C:\>

Invoking Java from NexJ Scheme

With its core being written in Java, the NexJ Scheme engine allows transparent invocation of Java code while being free of typing.

NexJ Scheme uses Java reflection to examine all public methods and fields that are available on a Java class. The following transformations are performed on method names:

You can use the Scheme function (import <fullyQualifiedJavaClass>) to make that class accessible to the Scheme engine. Once imported, you can refer to the variable <fullyQualifiedJavaClass> to affect static fields, use methods, and invoke its constructor using the 'new member. For example:

   (import 'java.util.ArrayList)
   (define numbers (java.util.ArrayList'new))
        
   (for ((i 0)) (< i 10) (set! i (+ i 1))
          (numbers'add i)
   )
        
   (for ((it (numbers'iterator))) (it'hasNext) ()
          (write (it'next))
   )

Determining NexJ Scheme Version

The version of the NexJ Scheme engine you are running can be accessed from its engine code:

   (import 'nexj.core.version.Version)
   (nexj.core.version.Version'RELEASE)

Exiting the NexJ Scheme Console

There are various ways to exit the interpreter. Depending on which console you are using, you may have different results: