Last week, at the Montreal Scheme/Lisp User Group, Marc Feeley gave a very interesting talk. He explained, in 90 minutes, how to write a simple Scheme to C compiler that supports full closures and cheap continuations (thus the title of the presentation). It is definitely a must read. At least to understand how continuations work.
The presentation is available in PDF, as well as the complete source code of the compiler, and AVIs of the whole presentation.
Friday, October 29, 2004
Friday, October 22, 2004
Designing new languages
In a (not so) recent post, Matthew Morgan expressed his desire to develop his own programming language. I think it's a legitimate goal. It has been mine also for the past 15 years (although not always as consciously as now).
But I never had time to pursue this goal seriously, for good or not so good reasons. However, I find myself designing new DSLs (domain-specific languages) at work whenever possible. This way, I can program at the right level of abstraction. They are not general-purpose programming languages, of course, but they often incorporate concepts like lexical scoping, inheritance, etc. Developing a good DSL that captures the right abstractions is hard, but it is almost as satisfying as designing a new programming language.
But the most important thing is this: since most of these DSL I use are written in Scheme on top of Scheme (thanks to macros), they can be freely mixed. In the same source file, I can have code that interfaces to a database using SchemeQL, and some unit tests expressed using SchemeUnit, and finally an LALR(1) parser.
Contrast this with the embedding of SQL statements in Java, using SQLJ, combined with a parser developed with ANTLR. These tools are great... for Java. But they greatly complexify your build process. Each source file has to be fed to a special-purpose source-to-source translator/compiler. And no source file can contain scripts for SQLJ and ANTLR at the same time. (This is certainly a contrived example, but it supports my claim.)
But I never had time to pursue this goal seriously, for good or not so good reasons. However, I find myself designing new DSLs (domain-specific languages) at work whenever possible. This way, I can program at the right level of abstraction. They are not general-purpose programming languages, of course, but they often incorporate concepts like lexical scoping, inheritance, etc. Developing a good DSL that captures the right abstractions is hard, but it is almost as satisfying as designing a new programming language.
But the most important thing is this: since most of these DSL I use are written in Scheme on top of Scheme (thanks to macros), they can be freely mixed. In the same source file, I can have code that interfaces to a database using SchemeQL, and some unit tests expressed using SchemeUnit, and finally an LALR(1) parser.
Contrast this with the embedding of SQL statements in Java, using SQLJ, combined with a parser developed with ANTLR. These tools are great... for Java. But they greatly complexify your build process. Each source file has to be fed to a special-purpose source-to-source translator/compiler. And no source file can contain scripts for SQLJ and ANTLR at the same time. (This is certainly a contrived example, but it supports my claim.)
Tuesday, October 12, 2004
Gambit-C 4.0
Gambit-C 4.0 is available! It's still a beta release, but knowing Marc Feeley personally, it wouldn't be out if he wasn't really confident about the stability of the whole system.
This new version offers lots of improvements over the previous release (3.0). But there are two noteworthy new features in this release:
Let me give an example of the latter. In Gambit-C 4.0, server sockets are created using the
In other words, ports are used as a generalized iteration mechanism. That's very cool.
Gambit-C has always been my favorite Scheme implementation, for a number of reasons (exceptional debugging support being the first). Now that it is released under the Apache license, it's more appealing than ever to use it in a commercial setting. I'm sure it will gain a new momentum in the Scheme community.
This new version offers lots of improvements over the previous release (3.0). But there are two noteworthy new features in this release:
- very efficient threads (I already wrote about them here), and
- unusual use of ports to represent some data structures, like directories, server sockets, FIFOs, etc.
Let me give an example of the latter. In Gambit-C 4.0, server sockets are created using the
open-tcp-server procedure. This procedure, when invoked on a TCP port number, returns an (input) server port. When one attempts to read from this port, it blocks until a client connects to the server. The value returned by read is a bidirectional port that allows the application to communicate with the client. More concretely, here is how one writes a client-server application in Gambit-C:
(define *server-port* 8080)
(define (run-server)
(let ((server-port (open-tcp-server *server-port*)))
(let loop ()
(let ((connection (read server-port)))
(process-connection connection)
(loop)))))
(define (process-connection connection)
(let ((request (read-line connection)))
(process-request request connection)
(close-port connection)))
In other words, ports are used as a generalized iteration mechanism. That's very cool.
Gambit-C has always been my favorite Scheme implementation, for a number of reasons (exceptional debugging support being the first). Now that it is released under the Apache license, it's more appealing than ever to use it in a commercial setting. I'm sure it will gain a new momentum in the Scheme community.
Saturday, October 02, 2004
Lisplets
Rich Hickey has written Lisplets, a very nice Java Servlet that forwards HTTP requests to another process over sockets using a Lisp syntax. The response headers are also sent back to the servlet using a Lisp syntax.
This provides an easy way to add an HTML interface to an existing Scheme/Lisp application, or to write a new Web application in Scheme/Lisp. The idea is really similar to something I described a few months ago. I haven't tried it yet, but I plan to do so in the next couple of days.
This provides an easy way to add an HTML interface to an existing Scheme/Lisp application, or to write a new Web application in Scheme/Lisp. The idea is really similar to something I described a few months ago. I haven't tried it yet, but I plan to do so in the next couple of days.
Subscribe to:
Posts (Atom)



