
Chicken Scheme Websockets - thecombjelly
http://wiki.call-cc.org/eggref/4/websockets#quick-start-example
======
AlexanderDhoore
Chicken Scheme uses a technique called "Cheney on the M.T.A." to implement
it's garbage collection (and entire language, really). It's one of the most
mind-bending things I've ever heard of.

Here's the article:
[http://home.pipeline.com/~hbaker1/CheneyMTA.html](http://home.pipeline.com/~hbaker1/CheneyMTA.html)

~~~
thecombjelly
Here is an article discussing the utilization of this technique specifically
for CHICKEN scheme.

[http://www.more-magic.net/posts/internals-gc.html](http://www.more-
magic.net/posts/internals-gc.html)

~~~
Direct
This and the paper above were extremely entertaining reads. To the point that
I am downloading CHICKEN right now to start exploring. Thank you for those
links.

------
davexunit
The example echo server is very elegant.

    
    
      (with-websocket
        (lambda ()
          (send-message (string-append "you said: " (receive-message)))))
    

I'll add "porting Chicken web sockets to GNU Guile" to my ever growing todo
list.

~~~
thecombjelly
Thank you. (I'm the author of the library.) It came about after quite a few
tries at a good API and with a lot of feedback from other CHICKEN hackers.

It probably isn't very portable right now, unfortunately. It uses a lot of
CHICKEN specific things to increase speed and memory efficiency but I'm
totally open to making it more portable.

~~~
davexunit
>It came about after quite a few tries at a good API

I'm very familiar with that cycle. I'm writing a game engine in Guile and I am
constantly implementing something, throwing it away, and trying again. Every
time you get a bit closer to the API you really want.

>It probably isn't very portable right now, unfortunately.

That's alright. Portable Scheme is cool, but I prefer using what the
implementation gives me instead of restricting myself to RnRS. Especially so
for something like networking code.

I might never get around to it, but if I find myself wanting to tackle a new
project, I'll give porting this a try.

------
baby
Why are people still using languages like scheme? I learned that in university
and always hated all those parentheses and thought I would never have to use
it again.

~~~
glibgil
Languages like scheme and lisp do not have real syntax, but are more like
abstract syntax tree markup languages. That is both the appeal and the
dissuasion. Attempts have been made to create syntax for these languages, but
it never catches on.
[https://www.google.com/webhp?#q=alternative+syntax+lisp+%7C+...](https://www.google.com/webhp?#q=alternative+syntax+lisp+%7C+scheme)

~~~
foobarbaz1234
I am a fan of Scheme but never got that statement. Why do people say
Scheme/Lisp has no syntax? I mean clearly it has a _simple_ syntax, i.e. an
expression is either an atom (an identifier, a number, a lambda expression,
etc.) or a list of expressions, denoated by "(expr0 expr1 ... exprN). I would
say it has a simple, well-thought and powerful syntax.

~~~
taylanub
It has no syntax (of its own) in that it hijacks s-expression syntax instead.
When you want to write Lisp code, you actually write some data structures in
the s-expression data format, like when writing some data in JSON or XML. Then
a Lisp interpreter or compiler uses an s-expression parser to read that data
structure into memory, and operates on that.

Then again, not just every Lisp dialect but even pretty much every
implementation has its own s-expression parser with its own extensions to
s-expression syntax to make it most convenient to write code in, so there's
not a very good decoupling after all. :-P Nevertheless it provides some
benefits. Like being able to use something like "paredit" to edit code
structurally, and making macro systems somewhat simpler (though hygienic macro
systems cannot work with pure s-expression data; it must be annotated with
lexical context).

You might find it hard to believe but I _love_ Lisp syntax with all of its
parentheses, and am explicitly against, for example, Sweet Expressions
(SRFI-110). (Though SRFI-105 is fine.)

By the way another meaning of the word "syntax" actually refers to something
within the data structures after the actual concrete syntax has been parsed
away. For example when you have a list and its first element is the symbol
"if", then that list is a usage of the if syntax. This syntax takes three
arguments (further elements of the list): a test, consequent, and alternative.
So "syntax" is something like a function here, except it operates during
compilation and its arguments are unevaluated sub-structures (roughly, code
snippets, though the syntax could interpret them however it wants, like for
example how the "lambda" syntax's first argument is a parameter list). That's
why we can say "in other languages you can only implement new functions; in
Lisp you can also implement new syntax." (In the form of macros.)

~~~
foobarbaz1234
> It has no syntax (of its own) in that it hijacks s-expression syntax
> instead. When you want to write Lisp code, you actually write some data
> structures in the s-expression data format, like when writing some data in
> JSON or XML. Then a Lisp interpreter or compiler uses an s-expression parser
> to read that data structure into memory, and operates on that.

My point is that the s-expression format has to be defined (obviously), e.g.
you enclose lists in '(' and ')' characters, space symbols separate tokens,
etc. In my world these rules are consequences of a defined syntax and saying
there is no syntax is just wrong. The reader parses at some point a byte
sequence and builds an AST. That Lisp/Scheme has such a simple syntax is a
powerful feature of the language but saying it has no syntax just contributes
to the belief of misinformed people that Lisp is some kind of strange Voodoo-
language which is a bad thing as it is a powerful tool.

