R7RS comes to Akku

Written by Gwen Weinholt on 2018-06-10

I have made some strides with Akku.scm since the introductory blog article and the announcement on the Chez Scheme mailing list. The big feature on the horizon is support for translating R7RS libraries to run on R6RS.

But first of all I need to apologize for building version 0.2.3 with libncurses6. Chez Scheme uses ncurses for its expression editor and Debian sid, which I use, has just had a migration from libncurses5 to libncurses6. Most Linux systems do not have that version of ncurses yet, so many of you could not get the pre-compiled version of Akku to run (the +src version works). I will have this fixed for the next release.

So what is this about translating R7RS to R6RS? The subset of R7RS that already exists in R6RS is quite large and the incompatible bits are manageable. Anyone interested in the details can read Implementing R7RS on an R6RS Scheme system (Kato, 2014). There are some syntactical differences, so a new reader is needed and the define-library forms need to be translated into library forms. Lastly the R7RS standard library needs to be implemented.

For this purpose I’ve written a reader called laesare that can handle both R6RS and R7RS. The bulk of the reader already existed and I added support for the R7RS lexical syntax. Next I added code to Akku to have it understand R7RS libraries and translate them to R6RS libraries. The final piece of the puzzle is the akku-r7rs package that provides the standard library. The latter is based on yuni by okuoku, with my own additions.

Some trickery was needed to support include and cond-expand. The include form in R7RS is somewhat loosely specified and leaves it up to the implementation to decide how to search for the files, but in practice the file paths are relative to the file where the include form appeared. This is not trivial to get working in straight up R6RS, but is easy with some help from Akku.

The next release of Akku will install the (akku metadata) library that describes all the libraries and assets (i.e. included files) that exist in the project. The include form uses this library to look up the location of the referenced files:

(define installed-assets
  '(((include "match/match.scm")
      ("chibi/match/match.scm")
      (chibi match))
    ...))

The location is relative to the library search path, which is how all R6RS include forms already do the job today. The metadata library also contains a list of installed libraries so that cond-expand library clauses work. These tricks work because Akku is project-oriented: it has full knowledge of all files it has installed.

Currently the R7RS support works with Chez Scheme. There is a slight problem with Racket: it has its own (scheme *) modules. Other implementations either already have R7RS support (Sagittarius and Larceny) or they don’t have a compatibility library in akku-r7rs and/or chez-srfi.

Another fly in the ointment is that many of the packages in Snow require implementation-specific code, which doesn’t exist yet for R6RS implementations. Hopefully that will change if Akku gains some popularity.

And finally, a bit of news for everyone who wants to use the git master version of Akku: you no longer need to manually bootstrap the dependencies. See CONTRIBUTING.md for instructions. Happy hacking!