Whalesong: a Racket to JavaScript compiler

Whalesong is a compiler from Racket to JavaScript; it takes Racket programs and translates them so that they can run stand-alone on a user’s web browser. It should allow Racket programs to run with (hopefully!) little modification, and provide access through the foreign-function interface to native JavaScript APIs. The included runtime library supports the numeric tower, an image library, and a framework to program the web in functional event-driven style.

The rational for returning the identity for expressions such as (*) and (+)

This post in comp.lang.scheme brings up a question that inevitably everyone asks.
Suppose the answer is obvious but John summed it up well:

Well, if you interpret (apply + some-list) and (apply * some-other-list) as left-folds, then a starting point is needed, something to begin accumulating from. The identity is the only value that works correctly, so it’s what gets returned when the list being folded over has length 0. Nobody would write (+) or (*) explicitly, but having them return the identity is the Right Thing nevertheless.
The same argument applies when expanding macros: in a degenerate case, a macro may expand to (+) or (*), and it’s usually not appropriate to raise an exception.

R7RS Initial Results of Implementor Intentions Poll

The following all intend to support R7RS small:

  • Per Bothner (Kawa)
  • Will Clinger (Larceny)
  • Shiro Kawai (Gauche)
  • Manuel Serrano (Bigloo) – “not sure about libraries”
  • Alex Shinn (Chibi) – “already fully implemented, but lacking tests”
  • Felix Winkelmann (Chicken)

The following were less committal, but open, and their implementations are flexible enough to implement R7RS in third-party code:

  • Kent Dybvig (Chez) – “if it’s as simple as you say I don’t see why not”
  • Matthew Flatt (Racket) – “if there’s sufficient user demand”
  • Andy Wingo (Guile) – “probably”

The following are simply unable to implement R7RS or uninterested in standards:

  • Taylor Campbell (MIT) – “MIT lacks the infrastructure for modules”
  • Jonathan Shapiro (TinyScheme) – thinks call/cc should be removed
  • Jeffery Mark Siskind (Stalin) – “no longer working on Stalin”
  • Michael Sperber (Scheme48) – “no time even for R6RS”

No one refused to implement based on the content of the standard, or cited any features as showstoppers.

That last part is important; R6RS didn’t have that quality.

(via scheme-reports)

Destructuring Lists Using CA*D*R vs First, Second, … vs Pattern Matching

This thread discusses the pros and cons of using the CA*D*R functions vs named first, second, third, list-tail, … and so on vs pattern matching for the same task.
I thought that pattern-matching was the best way to do it; and now I’m curious about why CA*D*R is better.

DSLs are still fun

Now the popularity of DSLs may have waned, but the fun surrounding them surely has not.
A while back James and I looked into implementing a DSL for modeling insurance products in Java that worked really nicely:

  • built on top of Java we’ve full access to all its goodies like the libraries and object system and containers
  • integrates with Eclipse to get code-completion and error-reporting and intelligent-debugging
  • open-source so we can tweak and bug-fix as needed

If that is your cup of tea, you might have a look at this super awesome tutorial on implementing a brainf*ck interpreter on top of the Racket programming language:
http://hashcollision.org/brainfudge/
Basically you get all the power of what Racket has to offer as a language, its libraries, it’s IDE, and the great users.
The article is sort of funny in that the first version of the DLS was deemed “too slow” at 37 second vs 16 second for the version running on the PyPy interpreter; so the author went about optimizing it with all sorts of tweaks that are might be inappropriate for an entry-level article, but for bragging rights… dropping its benchmark speed down to 1 second.