Sweet:   an alternative to s-expressions
7.7

Sweet: an alternative to s-expressions

Asumu Takikawa <asumu@racket-lang.org>

This manual describes the sweet package, a Racket port of the sweet reader by David Wheeler. This packages provides the sweet reader as a language mixin, similar to the at-exp or s-exp modules.

 #lang sweet-exp package: sweet-exp-lib

To use sweet expressions, supply a #lang line like the following:

#lang sweet-exp racket
 
printf("Hello")

The third parameter on the #lang line is the base language used by the language mixin. The resulting language will use the bindings from the base language, but support sweet expression syntax. You can provide any language here such as racket, typed/racket, or others.

For example:

#lang sweet-exp typed/racket
 
define: fact([n : Integer]) : Integer
  if zero?(n)
     1
     {n * fact{n - 1}}

Or alternatively:

#lang sweet-exp lazy
 
define fibs
  cons 0 cons(1 map(+ fibs cdr(fibs)))
 
displayln list-ref(fibs 8)

Known issues: quasi-quotation combined with grouping does not behave according to the specification.