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:
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
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:\>
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:
setPropertyX(Object value)
is accessible in Scheme as (instance'propertyX value)
getPropertyX()
is accessible in Scheme as (instance'propertyX)
isPropertyX()
is accessible in Scheme as (instance'propertyX)
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)) )
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)
There are various ways to exit the interpreter. Depending on which console you are using, you may have different results:
(java.lang.System'exit 0)