jsint
Class Scheme

java.lang.Object
  |
  +--jsint.Scheme

public class Scheme
extends java.lang.Object

This class represents a Scheme interpreter.

Author:
Peter Norvig, Copyright 1998, peter@norvig.com, license subsequently modified by Jscheme project members licensed under zlib licence (see license.txt)

Field Summary
static java.lang.String[] ARGS
          The main() arguments
static Symbol EVAL
           
static Symbol LOAD
           
 
Constructor Summary
Scheme()
           
 
Method Summary
static java.lang.Object analyze(java.lang.Object x, DynamicEnvironment dynamicEnv, LexicalEnvironment lexenv)
          Analyze (or preprocess or precompile) an expression into "code".
static Evaluator currentEvaluator()
           
static void defaultMain(java.lang.String[] files)
          The default main() behavior.
static java.lang.Boolean environmentImport(java.lang.Object x, java.lang.Object prefix)
           
static java.lang.Object eval(java.lang.Object x)
          Evaluate an s-expression in the global environment.
static java.lang.Object eval(java.lang.Object x, java.lang.Object env)
          Evaluate an s-expression in a lexical environment.
static java.lang.Object evalToplevel(java.lang.Object x, DynamicEnvironment env)
          evalToplevel evaluates each element of a BEGIN.
static java.lang.Object execute(java.lang.Object x, LexicalEnvironment lexenv)
          Evaluate analyzed code in a lexical environment.
static java.io.PrintWriter getError()
           
static DynamicEnvironment getInitialEnvironment()
           
static InputPort getInput()
           
static DynamicEnvironment getInteractionEnvironment()
           
static DynamicEnvironment getNullEnvironment()
           
static java.io.PrintWriter getOutput()
           
static void interruptCheck()
          Maybe interrupt this thread of execution.
static boolean isInterruptable()
           
static java.lang.Boolean languageImport(java.lang.Object x)
           
static java.lang.Object load(InputPort in)
           
static java.lang.Object load(java.lang.Object fileName)
          Eval all the expressions in a file.
static DynamicEnvironment loadEnvironment(java.lang.Object x)
          load the current file (or class) into a new initial environment and return the resulting DynamicEnvironment.
static boolean loadInit()
           
static void main(java.lang.String[] files)
          The following steps are performed If an "init.scm" resource or file is found, it is loaded.
static java.lang.Object[] makeArgArray(Procedure p, Pair args)
          Convert a list of arguments into an array expected by the procedure.
static InputPort open(java.lang.String name)
           
static InputPort openFile(java.lang.String name)
           
static InputPort openResource(java.lang.String name)
           
static InputPort openURL(java.lang.String url)
           
static Evaluator popEvaluator()
           
static void pushEvaluator(Evaluator i)
           
static void readEvalWriteLoop(java.lang.String prompt)
          Prompt, read, eval, and write the result.
static void runJscheme()
           
static void setError(java.io.PrintWriter error)
           
static boolean setExit(boolean exit)
           
static void setInput(InputPort input)
           
static void setOutput(java.io.PrintWriter output)
           
static java.lang.Object toBody(java.lang.Object exps)
          Handle internal defines, and convert a list of exps to a single exp.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ARGS

public static java.lang.String[] ARGS
The main() arguments

EVAL

public static Symbol EVAL

LOAD

public static Symbol LOAD
Constructor Detail

Scheme

public Scheme()
Method Detail

setExit

public static boolean setExit(boolean exit)

getInput

public static InputPort getInput()

setInput

public static void setInput(InputPort input)

getOutput

public static java.io.PrintWriter getOutput()

setOutput

public static void setOutput(java.io.PrintWriter output)

getError

public static java.io.PrintWriter getError()

setError

public static void setError(java.io.PrintWriter error)

isInterruptable

public static boolean isInterruptable()

interruptCheck

public static void interruptCheck()
Maybe interrupt this thread of execution.

currentEvaluator

public static Evaluator currentEvaluator()

pushEvaluator

public static void pushEvaluator(Evaluator i)

popEvaluator

public static Evaluator popEvaluator()

getInteractionEnvironment

public static DynamicEnvironment getInteractionEnvironment()

getNullEnvironment

public static DynamicEnvironment getNullEnvironment()

getInitialEnvironment

public static DynamicEnvironment getInitialEnvironment()

main

public static void main(java.lang.String[] files)
The following steps are performed

By putting the init.scm in a .jar file with the manifest entry:

 Main-Class: jsint.Scheme 
you get scriptable jar files that can be invoked by:
 java -jar name.jar
This idea was suggested by David May david@davudsplace.net.

By adding command line arguments or providing your own init.scm file you can override the init.scm file in the .jar to tailor your application.


defaultMain

public static void defaultMain(java.lang.String[] files)
The default main() behavior.

runJscheme

public static void runJscheme()

readEvalWriteLoop

public static void readEvalWriteLoop(java.lang.String prompt)
Prompt, read, eval, and write the result. Also sets up a catch for any RuntimeExceptions encountered.

loadInit

public static boolean loadInit()

load

public static java.lang.Object load(java.lang.Object fileName)
Eval all the expressions in a file. Calls load(InputPort).

loadEnvironment

public static DynamicEnvironment loadEnvironment(java.lang.Object x)
load the current file (or class) into a new initial environment and return the resulting DynamicEnvironment.

environmentImport

public static java.lang.Boolean environmentImport(java.lang.Object x,
                                                  java.lang.Object prefix)

languageImport

public static java.lang.Boolean languageImport(java.lang.Object x)

open

public static InputPort open(java.lang.String name)

openURL

public static InputPort openURL(java.lang.String url)

openFile

public static InputPort openFile(java.lang.String name)

openResource

public static InputPort openResource(java.lang.String name)

load

public static java.lang.Object load(InputPort in)

evalToplevel

public static java.lang.Object evalToplevel(java.lang.Object x,
                                            DynamicEnvironment env)
evalToplevel evaluates each element of a BEGIN. This is so macros can be defined and then used. Also toplevel macros can expand into begin.

eval

public static java.lang.Object eval(java.lang.Object x)
Evaluate an s-expression in the global environment.

eval

public static java.lang.Object eval(java.lang.Object x,
                                    java.lang.Object env)
Evaluate an s-expression in a lexical environment. First analyze it.

analyze

public static java.lang.Object analyze(java.lang.Object x,
                                       DynamicEnvironment dynamicEnv,
                                       LexicalEnvironment lexenv)
Analyze (or preprocess or precompile) an expression into "code". The code returned is either a Symbol, a LocalVariable, a Closure, or an array whose first element is either one of (quote if or begin set!) or is code evaluating to a procedure.

execute

public static java.lang.Object execute(java.lang.Object x,
                                       LexicalEnvironment lexenv)
Evaluate analyzed code in a lexical environment. Don't pass this a raw s-expression; you need to analyze the s-expression first.

makeArgArray

public static final java.lang.Object[] makeArgArray(Procedure p,
                                                    Pair args)
Convert a list of arguments into an array expected by the procedure. (See apply for an explanation of what is expected.)

toBody

public static java.lang.Object toBody(java.lang.Object exps)
Handle internal defines, and convert a list of exps to a single exp. Examples: (x) => (begin x), (x y) => (begin x y), ((define a 1) (+ a a)) => ((lambda (a) (begin (set! a 1) (+ a a))) #f)