Version 17 of Tcl in Javascript

Updated 2007-11-13 21:40:13 by suchenwi

Sarnold: I created a Tcl implementation in Javascript. The idea came from the need I felt to process documentation in wiki form in a browser - i.e., store manuals as wiki markup directly on the server, and let some Javascript code process it.

This idea is not new, many AJAX applications already do it. But remember, Tcl was created as a configuration language, and I need this type of language. But I wonder if I will ever have the time to finish it.

JsTcl - this implementation is far from being complete. I began it by looking at Picol's parser code, and converting it into Javascript.

Downloads.

You will need:

Supported platforms (browsers?)

This implementation was tested with Firefox 2.0.0.3 and IE 7.0 on Windows XP.

 puts {Really, Tcl runs everywhere!}

Differences with standard Tcl

Like in Picol, we have no expr. Instead, we have:

 + - * / % = !=

which operate on integers/reals, and

 not and or

which operate on booleans (there *is* a boolean type in this implementation).


RS: tcl.js is indeed a lovely baby, though so far poorly equipped (e.g. no loop commands like for, foreach, while...). I had to add

    this.registerEasyCommand("<", function (interp, args) {
        this.requireExactArgc(args, 3);
        var a = args[1].getNumber();
        var b = args[2].getNumber();
        return (a < b);
    });

or, simpler,

    this.registerEasyCommand("<", function (interp, args) {
        this.requireExactArgc(args, 3);
        return (args[1].getNumber() < args[2].getNumber());
    });

to get one of my favorite test cases through (ignore the backslash before * - Wiki is over-aggressive with that):

 proc fac x {
    if [< $x 2] {return 1}
    \* $x [fac [- $x 1]]
 }
 puts "fac 5 = [fac 5]"

But it wasn't hard - just a matter of copy'n'paste :^) On IE 5.50, the demo page didn't work, but it did in Opera 7.54 (except for source.. which lacked a good treatment for XMLHTTP). In any case, putting the test code right into jstcl.html works fine. Or using IE 6 on Win XP :^)

My latest version is tcl.js 0.2


See also: Picol