
Chicken Scheme - qwertyuiop924
http://call-cc.org
======
ane
CHICKEN is a lovely, pragmatic Scheme, it has a ecosystem that IMHO beats
other Schemes; you can easily compile executables, it has great package
management, testing systems. In that regard, it feels modern and complete,
like other contemporary languages. The only thing missing are lightweight
green threads.

~~~
qwertyuiop924
In a recent update, they added a debugger called feathers: it's a TCL script
included in the default distro, and it's very nice, IMHO, especially for a
debugger for compiled code: You can execute arbitrary code inside the current
stack frame, and inspect both the source and the compiled code, among other
things.

>The only thing missing are lightweight green threads.

...Ummm... Chicken already has that. It implements srfi-18 style pre-emptive
coroutines which do qualify as green threads by the standard definition. They
all run in a single thread, so you can parallelize without an explicit fork(2)
like you can in Erlang and Go, but they are Green threads.

~~~
ane
Oh _shit_ , I got it backwards: CHICKEN needs native threads! That way, you
could implement fibers.

[https://wiki.call-cc.org/man/4/faq#does-chicken-support-
nati...](https://wiki.call-cc.org/man/4/faq#does-chicken-support-native-
threads)

~~~
dig1
Or you can go with Gambit, which does superb job here and produces optimized
code. Last releases added backends for Java, PHP, javascript and perl I think.

~~~
qwertyuiop924
Gambit has exactly the same problem Chicken does: It has green threads
(Gambit's author actually wrote the API for it), but no native threads.

------
hellofunk
Chicken remains one of the most elegant and impressive implementations of any
concept in any programming language you will find. A true marvel of
engineering.

~~~
qwertyuiop924
True, but that's not why I use it. If it was, I would have moved to Cyclone,
which has improved Cheney on the MTA by adding threading support, and has a
library system that doesn't suck (with chicken, you have to generate import
files for every module in order for the system to compile or interpret your
code, even if the modules get compiled into a single file: it's like .h files
in C, but they're autogenerated. I usually use a make script to build them),
and a macro system that (afaik) isn't O(n) if you evaluate in the macro
environment by default.

But beyond the elegance of Chicken's internals, it's probably the most
practical Scheme implementation for just getting stuff done fast. It has
excellent C FFI, a good stdlib with solid POSIX bindings, an excellent package
repository with all the libraries you might need, and it's very fast. It's not
about the elegance, although it's there, it's about practicality: getting
stuff done, efficiently, effectively, and now, not later.

------
qwertyuiop924
Can I just take a moment to say how incredibly cool Cheney on the MTA is? Fast
continuations, and a really neat GC model: It's great.

~~~
CyberDildonics
What is 'the MTA'. Everything I tried to find just talked about 'Cheney on the
MTA' without ever defining Cheney or the MTA.

~~~
qwertyuiop924
_right_. Brace yourself, you're in for a long ride.

If you want to get in-depth on Cheney on the MTA, I'd reccomend Peter Bex's
article on the Chicken GC ([http://www.more-magic.net/posts/internals-
gc.html](http://www.more-magic.net/posts/internals-gc.html)), and the original
paper, "CONS should not CONS its arguments, part II: Cheney on the MTA". But
I'll do my best to sum it up here.

Cheney on the MTA is a really neat hack that allows for cheap continuations,
realtively efficient C compilation of Scheme code, and an effective garbage
collection scheme.

Effectively, with CMTA, you have a generational GC, but the first generation
is _stack allocated_. When the stack allocations run out of space, all the
data is copied out to the heap, into the second generation of GC. This is
super effective because most data is only allocated for a short time, so it
never goes out to heap, and your accesses are closer together, and also on the
stack, so there's less chance of a cache miss. But it gets better: In Scheme,
a program's continuation (think basically its instruction pointer and stack
state) can be reified as an actual data structure. However, since you're GCing
the stack already, this doesn't causr any overheard, or at least not nearly as
much as it does in, say, Guile, which has to copy the stack every single time
a continuation is created.

The reason it's called Cheney on the MTA is because it uses Cheney's algorithm
for GC, and because it's using the stack to hold data, popping the stack would
invalidate program state, so it _never returns_.

What never returning has to do with the MTA is a cultural alusion that would
take too long to explain here. But that's never stopped me before.

It's a reference to a song called "M.T.A", originally created for Walter O'
Brian's campaign in 1949 (Boston's subway was known as the MTA at the time).
It became a hit when recorded by The Kingston Trio in 1959. Looking up the
song is left an excercise to the reader.

Unofficially, the song is known as "Charlie on the MTA," hence the title of
the paper. And yes, this is where the CharlieCard gets its name.

The song is fairly entrenched in the area: I grew up in Connecticut, and know
the lyrics from memory. And on one of several trips to Boston, I've seen at
least one person expect to have to pay on their way out of the subway system
because of the song :-).

~~~
isxek
Thanks for this. I've seen the "CONS should not CONS" paper somewhere, but
skimming over it never really got me anywhere even close to this explanation.
I always thought it was some in-jokey reference to US politics, but I couldn't
connect the MTA concept.

~~~
qwertyuiop924

      Oh let me tell you a story about a function named *recursive* on a tragic and faithful time,
      It was called with 3 long ints, popped the stack and set a jumpbuf, called itself on the SGI.
    
      But did it ever return? No, it never returned, and its value is still unknown,
      It may run forever on the SGI mainframe, it's the function that never returned.
    
      Well that function ran a check to see when the stack would overflow, it ran almost past they say,
      But when it got there the function called a longjump on the jumpbuf,
      It just wasn't returning that day.
    
      But did it ever return? No it never returned, and its value is still unlearned
      It may run forever on the SGI mainframe, it's the function that never returned.
    

Man, GLS makes this look so easy. It's actually kind of hard.

------
wuschel
Chicken Scheme is a great Scheme implementation. For a beginner, however,
there is a lack of IDE e.g. a good guide how to get EMACS running for Chicken
Scheme. I used Sublime Text at the beginning, but I showed performance
problems when using the REPL.

~~~
jeff_petersen
> e.g. a good guide how to get EMACS running for Chicken Scheme

Did you see this? [http://wiki.call-cc.org/emacs](http://wiki.call-
cc.org/emacs)

Generally, for Schemes the standard is to use Geiser mode (not that you would
know that as a beginner)

~~~
qwertyuiop924
Geiser+scheme-mode+paredit, and maybe scheme-complete and flycheck, are the
way to go for all schemes. And geiser is great. It can just about give SLIME a
run for its money, which isn't something you can say about most modes.

------
gravypod
Does this compile to a binary? I'd love to see some sort of similar live-
compiler like [https://gcc.godbolt.org/](https://gcc.godbolt.org/) for this
language.

I've wanted to port my operating system attempts to some LISP-Like system but
I've not found a good Scheme implementation that generated nice and clean
assembly code.

~~~
qwertyuiop924
It actually generates C, which can then be pushed through the $CC of your
choice. Usually GCC. You can examine the generated C by passing a flag to the
compiler, telling it not to compile it beyond that stage. However, reading the
generated code isn't a task for the feint of heart: It generates CPS code, and
it uses Cheney on the MTA (a really bizarre hack thought up by Henry Baker,
and describe in his paper "CONS should not CONS its arguments, Part II: Cheney
on the MTA," which is essentially required reading if you want to even have a
hope of understanding what's going on.)

However, it makes heavy use of ELF and dynamic linking by default (although
you _can_ link statically), and libchicken, the runtime system, depends upon
libc by default.

So yes, you probably could make use of it for OS work, but it's not ideal for
that context.

------
sotojuan
I used chicken when doing SICP and Little Schemer. Loved it!

~~~
qwertyuiop924
Really? I'd use mit+edwin for that myself: it was the intended environment, so
everything works, and edwin is quite nice.

~~~
sotojuan
I'm not sure why I went for Chicken over the intended environment honestly, I
just did. It worked out well.

~~~
qwertyuiop924
It's R5RS, so it ought to work. I mean, you can use whatever scheme you want:
I was just surprised.

