A Joy implementation in Tcl

SA 2004-09-16: hi salvatore - in case you haven't been following the concatenative mail group, there's a general call out for short articles on the different cl's. manfred posted the following note this morning:

If you can read this, Salvatore, would you be interested to write a contribution to the joint paper about concatenative languages that we are writing? Your implementation seems to be significantly different from others, and your contribution to the paper would be most welcome.

  - Manfred

SS 2004-02-10: I used the last weekend to implement Joy in Tcl. It's not very fast of course, and still not complete, but does tail call optimization, has first class continuations, and is stackless (The interpreter never call itself), so it's simple to transfer an entire running program from an interpreter to another one.

Changelog

 2004-02-11 Now the implementation is a superset of Joy, that I called 'Apathy'. It's basically Joy with locals designed
            to don't break the Joy semantics. Now Joy primitives are implemented in Apathy and there are more primitives.

Too big to put it here on the Wiki, so download it from http://www.hping.org/tclsbignum/joy.tcl if you are interested.

Run it with

  tclsh joy.tcl

to use the interactive mode, or pass an file name to execute a program written in Joy.

As stated, it's still not finished. Many primitives are missing, but can easily implemented in Joy itself. Also note that currently the 'set' data type is missing.

Btw it is able to run this (From the Joy tutorial):

 DEFINE permlist ==
       [ small ]
       [ unitlist ]
       [ uncons ]
       [ swap 
         [ swons
           [ small ]
           [ unitlist ]
           [ dup unswons [uncons] dip swons ]
           [ swap [swons] cons map cons ]
           linrec ]
         cons map
         [null] [] [uncons] [concat] linrec ]
       linrec.

 [1 2 3 4 5] permlist

Use the help command to print a list of the defined words. Currently the following are defined:

 {} != * + - . / < <= = > >= and at auxpop auxpush body branch callcc character concat cons continue
 dip dup dupd exit first float help i ifte integer intern linrec list     local map newstack not null
 or pairlist pairstring pop popd pred primrec put putchars rem rest ret rolldown rollup rotate second
 size small stack stacktrace step string  succ swap swapd swons tailrec tclrepr third times truth uncons
 uncons2 unconsd unitlist unitstring unpair unstack unswons unswons2 while xor y

I plan to have a fully compatible interpreter in some day.