Jim

What Jim Tcl
Where http://jim.tcl.tk/
http://jim.tcl-lang.org (alternative URL)
https://github.com/msteveb/jimtcl (repository mirror)
Description Small footprint re-implementation of Tcl. Particularly suited for embedding. Currently at version 0.82.
Updated 2020-10-31
Contact See website

Recent Changes of this page and other news

  • 25 Feb 2023 Jim Tcl 0.82 has been released. See [L1 ]
  • 28 Nov 2021 Jim Tcl 0.81 has been released. See [L2 ]
  • 31 Oct 2020 Jim Tcl 0.80 has been released. See [L3 ]
  • 20 Nov 2019 Jim Tcl 0.79 has been released. See [L4 ]
  • 1 Jul 2018 Jim Tcl 0.78 has been released. See [L5 ]
  • 4 Sep 2016 Jim Tcl 0.77 has been released. See [L6 ]
  • 31 Jan 2015 Jim Tcl 0.76 has been released. See [L7 ]
  • 27 Feb 2014 Jim Tcl 0.75 has been released. See [L8 ]
  • 25 Jul 2013 Jim Tcl 0.74 has been released. See [L9 ]
  • 22 Dec 2011 Jim Tcl 0.73 has been released. See [L10 ]
  • 12 Nov 2011 Official website has moved to http://jim.tcl.tk/
  • 8 Nov 2011 Jim Tcl paper presented at Tcl/Tk 2011 is available at [L11 ]
  • 6 Oct 2011 Jim Tcl 0.72 has been released. See [L12 ]
  • 24 Jun 2011 Jim Tcl 0.71 has been released. See [L13 ]
  • 14 Apr 2011 Jim Tcl 0.70 has been released. See [L14 ]
  • 14 Apr 2011 Repository now mirrored at https://github.com/msteveb/jimtcl
  • 17 Nov 2010 Jim Tcl now supports UTF-8. See [L15 ]
  • 29 Oct 2010 Jim Tcl 0.63 has been released. See [L16 ]
  • The official source repository is now in GIT at http://repo.or.cz/w/jimtcl.git
  • View the most recent documentation at: Tcl_shipped.html

Index

Features

  • Jim Tcl is small. Between 100k and 200k depending on enabled options
  • Jim Tcl is modern. It supports {*}, dict, IPv6, TIP 288 (args anywhere in a proc's arguments), $(...) as a shorthand for expr, live stack traces and error reporting with accurate line numbers.
  • Jim Tcl is embeddable. Using autoconf, builds and runs on arm, mips, nios, x86 and more. Supporting Linux, FreeBSD, OpenBSD, Mac OS X, eCos, cygwin, mingw32 and more.
  • Jim Tcl has lambda with garbage collection.
  • Every kind of Jim procedure is also a closure, thanks to support for static variables.

Applications using Jim

  • Open On-Chip Debugger (OpenOCD)
  • USB Modeswitch [L17 ]
  • Ebindkeys, a linux program for binding key-presses or key-combos. [L18 ]

Jim Static Variables

  • Jim's static vars are trivial to use. Simply, proc can accept an optional statics list after the usual arguments list. Example:
 . proc foo {increment} {{value 0}} {incr value $increment}
 . foo 1
 1
 . foo 1
 2
  . foo 10
 12
  • If a static var is not initialized explicitly, the initial value is taken from the variable name with the same name in the local context:
 . set x 10  
 10
 . proc bar {} x {puts $x}    
 . bar
 10
  • Closure, Garbage collection, lambdas, makes Jim the first Tcl implementation where it's trivial to build the Paul Graham's well known accumulator function:
 # Write a function foo that takes a number n and returns a function that
 # takes a number i, and returns n incremented by i. Note: (a) that's number,
 # not integer, (b) that's incremented by, not plus.

 proc accumulator n {
    lambda increment n {
        set n [expr {$n+$increment}]
    }
 }

 set f [accumulator 100]
 puts [$f 10]
 puts [$f 20]
 puts [$f 1.25]

The output is

 110
 130
 131.25

RS: As Jim has prefix operators, I'd write it like this:

 proc accumulator n {
    lambda increment n {set n [+ $n $increment]}
 } 

Other Jim documentation in this Wiki

Commands already implemented

 . lsort [info commands]
 * + - / after alarm alias append array bio break case catch cd clock
 close collect concat continue curry debug dict env eof error errorInfo eval
 exec exit expr file {file copy} fileevent finalize flush for foreach format
 function getref gets glob global if incr info {info nameofexecutable} join
 kill lambda lambda.finalizer lappend lassign lindex linsert list llength
 lmap load local lrange lrepeat lreplace lreverse lsearch lset lsort open
 os.fork os.gethostname os.getids os.uptime os.wait package parray pid popen
 proc puts pwd rand range read readdir ref regexp regsub rename return scan
 seek set setref signal sleep socket source split stackdump stacktrace stderr
 stdin stdout string subst switch syslog tailcall tell throw time try unset
 update uplevel upvar vwait while
  • Jim has a simple to use references system to build arbitrary linked data structures, with garbage collection. The reference system can be also used to add automatic memory management to every other kind of object. For example Jim's lambda uses the reference system for garbage collection, and so will do the Jim's OOP system (if it is ever built).
  • Jim has dynamic loadable libraries.

Benchmarks

Here is a comparison of a recent (Oct 2010) version of Jim. Note that Jim appears three times, compiled with -O3, -O2, -Os.

 Jim benchmarks - time in milliseconds
                     Jim-O2 Jim-O3 Jim-Os 8.4.19  8.5.8  7.6p2  6.8.1 
           PI digits    544    444    618    282    326      F      F 
     [for] busy loop    216    230    234    164    144   2725   2347 
   [while] busy loop    406    373    489    165    147   2709   2304 
                 ary    303    280    311    139    175    459    402 
          ary [dict]    294    264    313      F    171      F      F 
        dynamic code    194    180    225    227    422    262    251 
 dynamic code (list)     80     69     91    102    136    336    312 
              expand     74     65     98      F    103      F      F 
       fibonacci(25)    286    265    338    153    188   1023    944 
            heapsort    214    199    244     98     72      F      F 
              mandel    339    281    341    199    215   2007      F 
          mini loops    204    190    235    165    134   2413   2086 
        nested loops    246    231    292     99     89   1842   1665 
              repeat    201    184    228   1641    893   2289   2054 
              rotate     29     29     35      F      F      F      F 
               sieve    401    358    433    115    180    800    712 
        sieve [dict]    357    300    397      F    202      F      F 
               upvar    226    209    304    196    171    460    407 
    wiki.tcl.tk/8566    416    380    487    165    158      F 

Note that if you plan to write very dyamic code, with a lot of eval/upvar, Jim is probably currently the faster of the three. (See the repeat test).

The source for the benchmarks can be found in the repository as bench.tcl

License

Jim is under the "2 clause" FreeBSD Licence. This means that it's GPL compatible, but like Tcl itself can be used in commercial software without need to distribute the modified source code. In one word Jim is free for both the opensource and the commercial world!.

Commercial Support

Salvatore Sanfilippo, the main author of Jim, will be glad to support in the extension and integration of Jim in embedded systems, as scripting language of existing application, and any other need. For more information write an email to antirez at gmail dot com.

Steve Bennett, the current maintainer of Jim can also provide support [L19 ]

Interested in Jim?

If you want to stay informed about Jim you can subscribe to the jim-devel mailing list. There is a web form to subscribe at http://jim.tcl.tk:8080/cgi-bin/mailman/listinfo/jim-devel . This is the primary forum for ongoing development of Jim. Also check the Jim development page.

Here is a place for your comments about Jim


02mar05 jcw - Jim is fascinating. Great engineering, IMO!

I've got an experimental reader for Metakit database files as well as a tiny Zlib decompressor based on the Vlerq project I'm working on. Should make it possible to support R/O starkits with very low footprint overhead (my guesstimate would be 25..35 Kb on top of Jim itself). The main issue is how to handle opens and globs and reads from things which are not files. As far as I can see, Jim has no I/O yet. Might be an idea to use a lightweight OO model ("$file read") so one can create objects that end up reading from a starkit. Could also be memory-mapped. Lots of ways to go from here...


SS 3-Mar-2005: Thanks for the good words! I followed the metakit discussion on the Feature Request thread but fortunately my lack of skills in metakits makes me unable to help from this point of view, with the exception that I can focus on the I/O extensions ASAP. For the OO, there will be Odys (with some change probably) integrated into the core (assuming I'll be able to implement it in max 1000 lines of code, otherwise I'll be forced to make it an extension, even if the Jim model is "little core, all extension" I really consider the OOP system to be a core language feature). Btw... I'm thinking that for starkits in unix-land another strategy that's possible to follow is to put POSIX I/O things into the jim-posix extension, and write an higher level interface directly in Tcl.

Yes, the Odys object system could work. No need for POSIX I/O if you *only* want to read from a starkit (which could make Jim secure, sort of). The code I have supports mem-mapped access on Windows, Linux, Mac OS X. -jcw


Steve Bennett Discussion on build systems moved to: Jim Tcl as a basis for configure and build system


Googie - How about speed? Are there any benchmarks available? I'm interested much in expr operations, but also others.

SS 2Mar2005: Hello Googie! Jim is currently slower than Tcl, but is faster than Tcl 7.6.


PT 3-Mar-2005: Jim supports dynamically loaded extensions. One of them supports a certain degree of COM automation under windows....

 load jim-win32com
 set ie [ole32 create InternetExplorer.Application]
 ole32.invoke $ie Navigate2 https://wiki.tcl-lang.org/jim
 ole32.invoke -put $ie Visible True

The above script results in Internet Explorer displaying this page.


SS 3-Mar-2005: That's cool! And is all merit of Pat. Also there is a start of win32 API binding. To hack with it:

  load jim-win32.dll
  info commands win32.*
  ...

SS 5Mar2005 - Update: in order to explore the proposal of SEH as well as the ability to run simple starkits with Jim, I'm working on a very simple Jim extension called AIO (Ansi I/O) that exports ANSI C file capabilities to Jim with a OOP Interface (and it is very simple to provide Tcl file API compatibility via some glue procedure). The initial version is on the CVS, people interested in this issue my follow the thread in the Feature Request at http://developer.berlios.de/feature/?group_id=3204 .

On the last days Jim reached a better shape, there are more core commands, it's more binary safe (now all the parsers are binary-safe), and robust. Also the exported C API is more complete.

That's how the AIO extension looks like:

 load jim-aio.so
 set f [aio.open /etc/passwd]
 set f2 [aio.open /tmp/FOOBAR w]
 while {[$f gets line] != -1} {
     $f2 puts "~~ $line ~~"
 }
 $f close
 $f2 close

Very similar to cfile.


LV Anyone have a table comparing features of Tcl and Jim, so that one can more easily understand the differences?

RS Jim is a rapidly moving target, but here's a quick sketch of what I can think of at the moment (see also Jim development for further differences):

  • Tcl, but not Jim: namespaces
  • Jim, but not Tcl: Jim closures - Jim references - lmap - prefix arithmetic operators - arrays are dicts are lists are strings - object-based I/O ...

On Jimulation I've started to "back-port" some useful Jim features to pure-Tcl, but most recently Jim seduces me to do even C fun projects... see below.


RS: See also Tiny OO with Jim - Jimulation / 2005-03-20: Here's this evening's fun project - adding an ** operator to jim.c (only added lines shown - "Doctor, somehow writing C doesn't hurt any more" :): ... snip... SS: ** added some time ago, thanks. For now it is supported only for integers because every mathlib related thing will probably go inside the math extension. This is so because the Jim core should not depend on the C math library.


RS was heard to aphorize, "Jim - because even simplicity can get simpler".


Felipe Voloch 5 Dec 2005 - I compiled Jim (binary here [L20 ]) for linux on the Jornada 680 handheld (from here [L21 ]). I wanted to compile Tcl but was having trouble with crosscompiling. Jim compiled and runs just fine. Nice stuff.


RJM 2010-10-16 I have put jim in the build tree of blackfin's uclinux-dist. It configures and builds right from the start correclty. I could for example successfully open and use a serial port (but opening pipes is apparently not supported yet).

Steve Bennett 26 Oct 2010 Great. pipes are supported. See: socket pipe, and the popen wrapper in tclcompat, which is used by open "|..."

Ask on the Jim mailing list if it isn't working.


MHo 2010-02-21: How to compile with MinGW???

Steve Bennett 26 Oct 2010 Now the same as all platforms:

  ./configure && make && make install

Best place for these questions is the Jim mailing list. http://jim.tcl.tk:8080/cgi-bin/mailman/listinfo/jim-devel


jSQLsh :

    jSQLsh is an SQLite shell based on the PostgreSQL command line shell.
    Implemented using the Jim Tcl interpreter. It is intended to be a simple
    light weight SQLite shell.

Aud By the sounds of it, Jim could be a potential Tcl 9.


MHo: What's definitely required is the possibilty to build jim-based starkits.


MHo: jim should support the glob switch -types!!


MHo 2014-10-23: Tcl:

% glob -directory d:/ -- *
d:/bootsqm.dat d:/home d:/htdocs d:/ipconfig-all.txt d:/mount d:/proxy.pac d:/temp d:/var
%

Jim (0.75):

. glob -directory d:/ -- *
bad option "-directory": must be -directory, -nocomplain, -tails, or --
[error] .

?????????

Steve Bennett - To MHo - glob.tcl is provided. If you want to support more Tcl options, feel free to make any changes you want. And optionally submit those to the mailing list for possible inclusion into the next release.


arjen - 2021-03-29 06:24:56

As a proof of concept, I wrote a very limited Fortran interface for Jim. The method I used allows me to do almost all coding in Fortran, rather than C as an intermediary. Of course, it is not really useful yet, but with a bit more work it should give the possibility to create extensions for Jim written in Fortran or use Jim as a scripting facility in Fortran programs. Mutatis mutandis I want to apply this technique to Tcl itself as well, to modernise my Ftcl package.


GS - 2022-12-11 - Does it exist a binary distribution for windows ? '''MiR - doesn't seem like there is any binary for windows out there. If I find the time I'll to compile win32 and put them on my github, stay tuned. OTH a pure Jim build doesn't really make that much sense, since it is thought to be integrated into larger apps :-) Uploaded a win32 binary [L22 ] Just the shell, none of the more fancy extensions... hope this helps. But I managed to include dynamic loading and compiled a working sqlite extension, that can be loaded into the interp.

Steve Bennett Note that the artifacts from the AppVeyor continuous integration builds for Windows are available: https://ci.appveyor.com/project/msteveb/jimtcl (except they only persist for 30 days). Now I have begun attaching the appveyor build when releasing Jim Tcl. e.g. https://github.com/msteveb/jimtcl/releases/tag/0.82