From: Timothy H. <tim...@ma...> - 2002-05-31 13:29:33
|
Hi, I was playing with your SISC applet (very nice!) and realized that we could use Jscheme to create an interface for the SISC interpreter. I haven't yet created a Jscheme applet for the SISC interpreter, but I've included below a simple Jscheme GUI. I thought it might be of interest to the SISC community to see how to different Java Schemes could work together. SISC seems to be written with R5RS conformance and high performance in mind, whereas Jscheme (jscheme.sourceforge.net) was designed to allow easy access to Java. It can be though of as a "Scheme skin" over Java.... Anyway, here is the little GUI You need to have both sisc.jar and jscheme.jar in your classpath and you issue the command % java -cp jscheme.jar:sisc.jar jscheme.REPL SISCgui.scm Note that all Jscheme symbols that contain a "." or a "$" are interpreted as Java constructors, methods, fields, etc using the Javadot notation (as shown on the jscheme.sourceforge.net page). ---Tim Hickey--- ================================= ;; SISC Gui ... (import "java.util.zip.*") (import "java.io.*") (import "sisc.*") (import "sisc.data.*") (import "sisc.contrib.applet.*") ;; initialize SISC (define in (GZIPInputStream. (BufferedInputStream. (FileInputStream. (File. "sisc.heap"))))) (define ctx (AppContext.)) (Context.register "main" ctx) (define r (Context.enter "main")) (REPL.initializeInterpreter r (list->array String.class '()) in) (Context.exit) ;; create a SISC REPL with a stream based interface ;; scheme terms sent using interpin ;; scheme results received using interpout (define interpout (PipedOutputStream.)) (define results (BufferedReader. (InputStreamReader. (PipedInputStream. interpout)))) (define interpin (PipedOutputStream.)) (define schemein (PrintWriter. interpin)) (define iis (PipedInputStream. interpin)) (define dynenv (DynamicEnv. (SourceInputPort. (BufferedReader. (InputStreamReader. iis)) "console") (OutputPort. (PrintWriter. interpout) #t))) (define repl (REPL. "main" dynenv)) ;; create a GUI (jlib.Swing.load) ;; load windowing library providing high level access to Swing (define results-ta (textarea 10 60)) (define userin (textarea 10 60)) (define evalbutton (button "eval" (action (lambda(e) (.append results-ta {\n\n---------------------------------\n[(readstring userin)] -->\n-----------------------------------\n}) (.println schemein (readstring userin)) (.flush schemein))))) (define (listener) (let loop () (let ((x (.readLine results))) (.append results-ta {[x]\n}) (loop)))) (define w (window "test" (border (west (col 'none 'north evalbutton (button "clear" (action(lambda(e) (.setText userin "")(.setText results-ta "")))) )) (center (vsplit 0.5 (scrollpane userin) (scrollpane results-ta)))))) (.pack w) (.show w) ;; start up the REPL and the listener (.start (Thread. listener)) (.start repl) |