00 | Previous | Up | Next
LISP -- a Language for Internet Scripting and Programming
Timothy J. Hickey, Brandeis University, Waltham, MA |
01 | Previous | Up | Next
Before we beginLisp at BBN:
These slides were formatted using CL-HTTP. |
02 | Previous | Up | Next
Overview
|
03 | Previous | Up | Next
Web programming is harder than it looks
|
04 | Previous | Up | Next
Design Goals - Students writing applets in 50 minutes
|
05 | Previous | Up | Next
The Primitive LISP-Java Interface
Example: use the isProbablyPrime() method of the BigInteger class to determine if a number is prime:
|
06 | Previous | Up | Next
Build your own additional metalevel access |
07 | Previous | Up | Next
Declarative GUI programmingDeclarative minilanguages are easy in Lisp:
JLIB interface to AWT: About 250 defining forms provide access to AWT. |
08 | Previous | Up | Next
Hello World ExampleCode follows shape of window. As easy as Tcl/TK. Limited, but idea for quick prototypes. More control can be gained by using the Lisp-Java interface or extending the Scheme API. |
09 | Previous | Up | Next
Body mass example |
10 | Previous | Up | Next
LISP AppletLISP Applets are similar to Java Applets: The jlib.Applet class uses the "program" parameter to find what LISP program to load. An alternative would be to compile LISP to Java |
11 | Previous | Up | Next
Interactive Java Debugging and Scripting
|
12 | Previous | Up | Next
Example: interacting with an interval arithmetic solverLift Java interval arithmetic solver into LISP: Interval Arithmetic |
13 | Previous | Up | Next
Example continued: exercise the solverAfter defining these procedures, we can interactively call these imported procedures and examine the results. |
14 | Previous | Up | Next
LISP can provide graphical interactionA few lines of LISP can provide a GUI for interacting or testing Java code. scripting Here is a GUI for the interval arithmetic solver: |
15 | Previous | Up | Next
Scheme Implementations+ Scheme is a powerful but tiny language. + 50 page manual + Scheme interpreters are easy to build and relatively efficient. + High performance compilation well understood. +/- Many Scheme implementations with broad range of performance |
16 | Previous | Up | Next
SILK design issuesOriginal version of SILK done by Peter Norvig Initially, 650 lines written in about 20 hours. Within a few months i could handle Aubrey Jaffrey's online r4rstest.scm test suite. Here is the initial class structure:
SchemePrimitives - Scheme code in a big string.
SchemeUtils - Scheme like static methods, cons, car, cdr, ...
Scheme - Interpreter.
Environment
Pair
InputPort
Procedure
Primitive
JavaMethod
Continuation
Closure
Macro
|
17 | Previous | Up | Next
Things you need to do to make a Scheme
|
18 | Previous | Up | Next
Primitive functionstwo approaches: Inner classes: new Primitive("list", env, 0, n) {
public Object apply(Object args) { return args; }};
new Primitive("null?", env, 1) {
public Object apply(Object args) { return truth(first(args) == null); }};
Big switch final static int ... LIST = 16, ... NULLQ = 23, ... // Define constants
...
public static Environment installPrimitives(Environment env) {
int n = Integer.MAX_VALUE;
env.defPrim("list", LIST, 0, n) // list has 0 to n arguments
...
.defPrim("null?", NULLQ, 1) // null? has exactly one argument
...;
}
public Object apply(Scheme interpreter, Object args) {
...
Object x = first(args);
switch(idNumber) {
...
case LIST: return args;
...
case NULLQ: return truth(x == null);
}
}
|
19 | Previous | Up | Next
Primitive data typesScheme has a dozen or so data types SILK uses the simplest simplest possible existing Java types:
|
20 | Previous | Up | Next
Implementation statistics
|
21 | Previous | Up | Next
Silk 1.0Designed to be tiny. Written in a compact Scheme style. Existing Java classes used wherever possible. Java null is the empty list. Extensions to Java are minimal. |
22 | Previous | Up | Next
Silk 2.0Silk 2.0 provided a higher performance evaluator by splitting eval() into two steps:
/** Evaluate an object, x, in an environment. First compile the
* meaning of the object, and then call eval method on the meaning. **/
public static Object eval(Object x, Environment env) {
return Code.eval(Code.toCode(x,env), Frame.EMPTY);
}
Tail recursion is accomplished by letting eval return a Code object:
static Object eval(Object expr, Frame f) {
if (expr instanceof Code) {
expr = ((Code)expr).eval(f);
while (expr instanceof Code)
expr = ((Code)expr).eval(Frame.EMPTY);
}
return expr;
}
Thus the inner loop of the interpreter is replaced by method dispatch. Currently, a relatively small number of Further performance can be gained by generating more refined classes to handle common special cases more efficiently. This is a simple form of peephole optimization. |
23 | Previous | Up | Next
SkijSkij is a Scheme advertised as a scripting extension for Java. Similar in capabilities to Silk 1.5 Extensive Java support including generic operations: (peek) and (poke) - reading/writing slots (invoke) and (invoke-static) - invoking methods (new) - object construction Scheme handles Java exceptions. Serializable |
24 | Previous | Up | Next
JajaBased on Christian Queinnec's wonderful book "Lisp in Small Pieces" Compiler written in Scheme 1/3 the size of a Java version. Comparable to Silk Written in a object oriented style. Like SILK, uses the shared superclass trick. Each Scheme type is one or more Java classes. nil is prepresented as an instance of Emptylist. All Jaja objects are serializable. |
25 | Previous | Up | Next
KawaAmbitious Scheme implementation. Java classes useable for implementing other languages. Scheme to Java byte code compiler. Each function becomes a Java class compiled and loaded at runtime.
|
26 | Previous | Up | Next
FutureGeneric Functions Compiler Meta scripting Network Citizen |
27 | Previous | Up | Next
Generic Functions
|
28 | Previous | Up | Next
CompilerSilk 1.4:
Silk 2.0
Scheme to Java compiler based on?
|
29 | Previous | Up | Next
Meta ScriptingA simpiler variant of a compiler: write Scheme procedures that generate new Java classes from old ones. Use reflection of existing class to construct a new one with additional capabilites. Example: Class Primitive implements 150 SILK primitives. Representing this knowledge in Scheme would let the class and its necessary glue code generated automatically. SILK would become even smaller. |
30 | Previous | Up | Next
Example: add tracing get and put of a specific hashtable;;; Access your Java application: (define app (.. your java application ...)) ;;; Extract a component of the applcation, here a table. (define table (get-field app "table")) ;;; Define a metawrapper class. (define wrapper-class (metawrap (class table))) ;;; Create new wrapped table. (define new-table (new wrapper-class table)) ;;; Trace the methods you want: (trace new-table "get") (trace new-table "put") ;;; Reinstall the table (set-field app "table" new-table) |
31 | Previous | Up | Next
What's going on?
|
32 | Previous | Up | Next
Network citizenship and Java integration
|
33 | Previous | Up | Next
Conclusion
|
|
34 | Previous | Up | Next
|
|
35 | Previous | Up | Next
The class structure for SILK 2.0 is shown below:
Object
Frame
SchemeUtils - Scheme like static methods.
Code - What things compile into.
Environment
GlobalEnvironment
LambdaEnvironment
InputPort
Pair
Procedure - Something you can apply().
Closure
Continuation
JavaArgs - Deals with Java arguments.
JavaConstructor - Java constructor, see (constructor).
JavaMethod - Java method, See (method).
Primitive - Primitive Procedure defined as big switch.
Scheme - Scheme main loop.
Syntax
SchemePrimitives - String containing scheme code.
Symbol
Throwable
Exception
RuntimeException
SchemeException
|