ITworld.com
  Search  
ITworld Home Page ITworld Webcasts ITworld White Papers ITworld Newsletters ITworld News ITworld Topics Careers ITworld Voices ITwhirled Changing the way you view IT

Scripting systems unite

Unix Insider 11/17/00

Cameron Laird and Kathryn Soraiz and Derek Lac, Unix Insider

unixinsiderhome
Kawa, a Scheme processor implemented in Java that emits Java byte code, was first released in early 1996. Don't confuse it with one of the first integrated development environments (IDEs) for Java, which appeared in the summer of 1996 under the same name. Kawa the IDE has been in the news recently because Allaire bought it from Tek-Tools in early November.

On this topic
>

One common observation about Scheme, and more generally about Lisp, is that it's insular. Critics agree that while Scheme is simple and elegant, it can be hard to get it to do anything useful in a commercial sense. One reason for this is that most Schemes support or bind to common APIs clumsily at best. The Scheme tradition has properly emphasized portability, intellectual rigor, and extensibility. However, this has often led to isolation from a particular platform's specific features and a tendency to reinvent the wheel.

Matthias Felleisen, self-described iconoclast and head of the Programming Languages Team at Rice University, is aware of this. He explains that the prospect of Scheme's commercial adoption distresses even some people that argue for it; according to Felleisen, they would be unhappy at no longer being able to change their favorite languages and experiment with new constructs, type systems, or module systems.

One quick way to bridge the API gap is to exploit Java's rich library and reflection capabilities. Interpretively combining Java and Scheme allows the Java APIs to multiply Schemers' productivity. The union also gives Java programmers a more congenial environment for experimental development, rapid prototyping, and automated class testing. Moreover, Scheme and its relatives remain the programming languages of choice in areas where Java is weak, such as artificial intelligence and advanced work in program verification.

Silk is an interpreter that combines Java and Scheme. It relies on naming conventions to make Java APIs visible in Scheme. Look at how "Hello, world" in Silk takes advantage of the Java Abstract Windowing Toolkit (AWT):


     (define (init thisApplet) 
       (main ())) 
     (define (main ShellArgs) 
       (define win (java.awt.Frame. "Hello World")) 
       (define quit (java.awt.Button. "quit")) 
       (.add win "Center" (java.awt.Label. "Hello World")) 
       (.add win "South"  quit) 
       (.addActionListener quit (Listener11. (lambda(e) (.hide win)))) 
       (.pack win) 
       (.show win) 
  

Silk executes this script directly in a Java virtual machine (JVM); a developer need not stop to invoke a byte-code compiler. Java reflection gives Silk the ability to query variables and immediately execute Java functions. The user enters a function name, and the JVM executes a sequence synthesized by reflection directly from the symbolic reference, instead of from the kind of byte-code object file that javac produces.

Silk can also construct new Java classes, access Java variables, and execute Java functions through its naming convention. A Silk script to create a Java object and refer to it by the name of its Java source variable is as simple as:


      (define str (java.lang.String. "hello")) 
      (.length str) 
    

The . appended to the end of the String class name tells the Silk interpreter to construct a new class instance by invoking the String constructor. String takes a string variable as its argument. The . prefixed to length signals the Silk interpreter to execute the Java method length with the argument str.

Silk handles user-defined classes with equal facility. Compile:


      package myclass; 
      public class SchemeAsOne extends Object { 
      }; 
    

This is visible within Silk as:


      (define scheme_class (myclass.SchemeAsOne. )). 
    

Silk in Java
All Scheme functions can be accessed within Java by using Scheme handlers. Within Java source code, for example, you might invoke:


     Symbol start = Symbol.intern(start); 
     Symbol canvas=Symbol.intern(canvas, 
           silk.Scheme.eval(new Pair(start, 
                new Pair( new Pair(canvas, new Pair (this, Pair.EMPTY))))); 
    

One clever use of Silk is to execute Scheme source through a URL stream:


      silk.Scheme.load(new InputPort(new URL(file:localprogram).openStream())); 
    

Because the entire Silk interpreter takes up only 50 KB, it's practical to represent Scheme source as Java applets embedded in Webpages.


      <html> 
       <APPLET code="silk.SchemeApplet"   
               codeBASE="."     
               WIDTH="100" HEIGHT="50" 
               ARCHIVE="silk.jar"> 
       <param name="prog" value="http:HelloWorld.silk">  
       <param name="init" value="init"> 
       </APPLET> 
       </html> 
    

silk.jar contains the Scheme interpreter. In this example, the Scheme source is in the filename HelloWorld.silk local to the server. It receives SchemeApplet as a parameter.

Silk development

Three programmers currently maintain Silk: Ken Anderson, Tim Hickey, and Peter Norvig. Norvig submitted a technical report on Silk to the Workshop on Scheme and Functional Programming 2000, which we mentioned in one of October's columns. Hickey, an associate professor of computer science at Brandeis University, teaches courses on Silk.

A decade ago, Scheme was often positioned as a competitor for C and C++, and more recently, to Java. Now it is poossible for Scheme to complement Java and C++. Silk is the best-positioned candidate to hybridize the procedural and functional strengths of Java and Scheme, respectively.

Learning from seniors
Several other readers wrote that Scheme deserves more attention from developers, if only because it's already weathered storms that other languages are only beginning to feel. We often mention Python, for example, and have encouraged it as an ideal first language. Python originated from educational research, and its Computer Programming for Everybody (CP4E) project has received considerable publicity. Still, classrooms have relied on Scheme for over 15 years, a record that dwarfs Python's.

Similarly, we've lauded Christian Tismer's Stackless Python. Many of the engineering choices involved in this reimplementation of Python can be traced directly to work done with Scheme (and with Icon and Forth) about a decade ago. Tismer is a rigorous thinker who recognizes that he stands on the shoulders of others.

For those not familiar with the scholarship of programming languages, we're happy "to give a little credit to people who've spent 20 years on a problem," as Shriram Krishnamurthi of Brown University pleads. Krishnamurthi also said that for the Scheme workshop, "We expected about half as many people as showed." Scheme is attracting more attention, and deservedly so.

Cameron Laird and Kathryn Soraiz manage Phaseit, a software consultancy just outside Houston.

Derek Lac is Webmaster for Oxygen Level, a site devoted to better gaming in Silk.




Sponsored Links

Dashboards & KPI Reporting for Business People
PivotLink provides a new perspective on your business with drillable dashboards & reports.
CAPTURE Quad-Core Performance
Check Out The Latest In Capturing The Value Of Xeon® Quad-Core Servers For Your Business.
SOLVE SUPPORT ISSUES on the First Call!
REMOTELY CONTROL AND CONFIGURE SYSTEMS. Easily install applications, updates. All from your Desktop!
FREE Application Discovery Tool from Sophos
Scan your network for VoIP, IM, games and other potentially unwanted applications.
FREE Sophos Threat Detection Test
Scan for viruses, spyware & adware. Is your AV catching everything?
» Buy a link now

Advertisements
Sponsored links
Locate Hidden Software on business PCs with this free tool
Bring harmony to your mix of UNIX-Linux-Windows computing environments
Top 5 Reasons to Combine App Performance and Security
KODAK i1400 Series Scanners stand up to the challenge
 Home   Application Development  Programming tools  Programming languages  Server Scripting  JavaScripting Pages (JSP)
www.itworld.com    open.itworld.com     security.itworld.com     smallbusiness.itworld.com
storage.itworld.com     utilitycomputing.itworld.com     wireless.itworld.com

 
Contact Us   About Us   Privacy Policy    Terms of Service   Reprints  

CIO   Computerworld   CSO   GamePro   Games.net   IDG Connect   IDG World Expo   Industry Standard   Infoworld   ITworld   JavaWorld   LinuxWorld  MacUser   Macworld   Network World   PC World   Playlist  

Copyright © Computerworld, Inc. All rights reserved

Reproduction in whole or in part in any form or medium without express written permission of Computerworld Inc. is prohibited. Computerworld and Computerworld.com and the respective logos are trademarks of International Data Group Inc.