» A great Scheme implementation that inspires interesting code constructs and bad puns.

After my rejection of newLISP, I looked around some more and found this: Chicken Scheme!

This is a non-sissy Scheme implementation which boasts, among other things:

Below are a few demonstrations of the power of Chicken.

Building and installing "eggs"

Installing new packages ("eggs") is essentially very easy (although problems might arise when they are dependant on third-party C libraries). To retrieve, build and install an egg named foo, this is basically all you need to do:

sudo chicken-setup foo

For example, Chicken does not support bignums and rationals out of the box. This is easily fixed by installing the numbers egg:

sudo chicken-setup numbers

Like all good package managers, chicken-setup will also notice dependencies and automagically download and install those as well.

(Note: numbers requires the GNU Multiprecision library (gmp). Since this is not an egg, it will have to be installed manually, if not already present. I ran into a slight problem here; the gmp downloaded at the location suggested by the numbers documentation appeared to compile OK, but Chicken had a problem with it during linking. Another version downloaded via MacPorts worked without problems.)

Using eggs

When you start the interpreter, the numbers package isn't available yet. Large integers are coerced to floats, and there is no support for rationals at this point.

#;1> (define (fac n)
        (if (<= n 1)
            (* n (fac (- n 1)))))

#;2> (fac 20)

#;3> 2/4
Warning: can not represent exact fraction - coerced to flonum

However, after we load the egg with require-extension, everything changes:

#;4> (require-extension numbers)
; loading /usr/local/lib/chicken/1/numbers.scm ...
; loading /usr/local/lib/chicken/1/ ...

#;5> (fac 20)

#;6> 2/4

To see which packages are available, peep Eggs Unlimited.

Mixing Scheme and C

Let's say we have some C code in twice.c:

int twice(int n) 
    return n * 2;

We can then write a simple Scheme interface and stick it in test.scm:

(define twice
    (foreign-lambda int "twice" int))

(...where the first int is the function's return value, and the second one is its only parameter.) Compile together to produce

csc -s test.scm twice.c

The resulting file can be imported and used by Chicken:

$ csi
#;1> (require-extension test)
; loading ./ ...
#;2> (twice 4)

Of course, linking to a library works as well, which opens the door to all kinds of possibilities. Basically, if it's written in C, you can write a Chicken interface for it.

There are other ways to mix Scheme and C. If it's just a matter of executing certain C code, then foreign-code can be used. Also, some tags like #> and <# allegedly have magic powers, but I haven't tested this yet. For more information, see the docs: Interface to external functions and variables.

Anyway. This is some great stuff. The power of Scheme, combined with the practicality and usefulness of a scripting language, without sacrificing the power of either. (Now if I could only figure out Scheme macros... :-)