Version 67 of Jacl

Updated 2005-11-08 07:13:53

http://tcljava.sourceforge.net/ is the home of Jacl. Jacl is an alternate implementation of Tcl 8.x, written entirely in Java. Jacl is production ready software, it is stable enough to be used in production systems on a daily basis.

Jacl and TclBlend are both implementations that make it easy to use Tcl scripting on the Java platform. The Tcl/Java project provides mailing lists [L1 ], online documentation [L2 ], and a bug reporting interface [L3 ].

Links to a number of Jacl and Tcl Blend related articles are also available [L4 ].

For help building Jacl under Windows, see Building JACL with msys.


According to this InfoWorld article[L5 ], Sun is thinking of introducing scripting to Java. Shouldn't they be encouraged to do this with Tcl? - escargo 12 Jun 2003 (The linked page did not display well with IE, but did with Mozilla.)

LV Sun has nothing to do with Tcl ... it has been long enough that the people still working there may not even remember that there was ever a Tcl and Sun connection.

It'd be great however if some of the Java heavies got on the Jacl band-wagon.


Swank is an interesting extension to Jacl. It was just updated during 2004.


CL occasionally updates a page [L6 ] of information related to Jacl. Note that much of the information on this page is out of date.


Has anyone figured out a way for Jacl apps to communicate with tcl/tk apps via a send like mechanism?

There is no support for send in Jacl.


For an informal comparison of how Jacl fared in a 2003 vote for favorite Java scripting language, check http://viva.sourceforge.net/republic/2004/01/scripting_language_of_the_year_2003_award_and_the_winner_is.html

schlenk With only 480 votes this can be hardly seen as relevant, perhaps we should hold such votings for Tcl too...


Summer 2004: "Tom Poindexter is working on a companion to Jacl (called Hyde) that compiles Java on the fly ..."


Running JACL under IBM RAD 6/Eclipse 3.1.

Patrick Finnegan 13/07/2005.

Someone at work asked me how to do this so here are some concise instructions with a trivial example for anyone else who wants to experiment with RAD6 or Eclipse 3.1.

Download RAD6 trial from:

http://www-128.ibm.com/developerworks/downloads/r/rad/?S_TACT=105AGX14&S_CMP=DWNL

Start RAD6 or Eclipse 3.1.

1. Create Java project.

2. Add the JACL jar files.

Add jacl.jar and tcljava.jar to the java build path under "project properties". The jar files are already packaged with RAD6 and can be found under the install directory e.g. "D:\IBM\Rational\ADTrial\6.0\runtimes\base_v6\lib\jacl.jar".

3. Create a top level java class.

Create a top level java class with a main method. Instantiate the tcl interpreter and use the Interp eval method to either run Tcl in-line or source Tcl from a file.

Example.

*

1. Run the tcl command in-line "puts clock format [clock seconds -format %k:%M:%S]"

2. Source the proc compare.

 proc compare {howmany value} {
   for {set i 1} {$i < $howmany} {incr i} {
      if {$i == $value} {
         puts $i
      }
   }
 }

 set bench 1000

 set bench2 [expr $bench - 1]

 puts "comparing an int against $bench others..."

 compare $bench $bench2

 ##############################################################################

 import tcl.lang.*;

 // Java wrapper to test JACL under RAD 6.

 public class ScriptRunnerTcl {
    public static void main(String []args) {

        Interp i = new Interp();

    try {

            i.eval("set x {The time is }");
            i.eval("set y [clock format [clock seconds] -format %k:%M:%S]");
            i.eval("puts [append z $x $y]");
            i.eval("puts \\n");
            } catch (TclException e) {
            System.out.println("Exception: " + e.getMessage());

            }

        try {
            i.eval("source E:/scripts/TCL/jacl/compare.tcl");
            } catch (TclException e) {
            System.out.println("Exception: " + e.getMessage());
            }


    }
 }

 #############################################################################

The output looks like:

 The time is 21:19:51


 comparing an int against 1000 others...

 999

BSF and JACL

BSF is the Bean Scripting Framework http://jakarta.apache.org/bsf/-- a way of adding a scripting engine to Java (or to call Java from a scripting engine).

While there are some references that describe how to use it ([L7 ], [L8 ], [L9 ], and [L10 ] among others), none of them read clearly and concisely enough (at least for one user).

In short

  • Download the BSF jar from Jakarta: [L11 ].
  • Download the Tcl/Java sources from sourceforge: [L12 ]
  • Build the JACL and TclJava jars (configure, make)
  • Add the jars to the classpath (in Eclipse, add them to the Project Properties -> Java Build Path -> Libraries)
  • Add an import for the BSF engine to the Java class where you wish to embed JACL:
 import org.apache.bsf.*;
  • Add code in the Java application to read the script file, then pass it as a string to the BSF manager:
            try {                
                BSFManager mgr = new BSFManager ();
                Object r = mgr.eval("jacl", scriptFile, 0, 0, script);           
                theUI.addLogText( "Return value: " + r.toString() + ", " + r.getClass().getCanonicalName() );      
            } catch(BSFException bsfe) {
                bsfe.printStackTrace();
            }

where "scriptFile" is the name of the file containing the script and "script" is that file's contents; the addLogText method on some Java UI object adds the text to a log window in the UI.

  • Read in the following "jacl" script and use the Java code above to interpret it:
 package require java
 puts "Hello world"
 return "Heellllo, world"
  • And "Hello world" shows up in the Java programs STDIO while the following line appears in the UI's log window:
 Return value: Heellllo, world, java.lang.String

Where at least one user went wrong was neglecting to add the TclJava jar to the class path, as well as the JACL jar (even though only JACL was all that was used, both jars were needed-- a tip which someone else thankfully put into a c.l.t. posting here: [L13 ]).


See also


Category Language | Category Java | Category Tcl Implementations