# [racket] Sweet expressions; or making it easier to introduce Racket to me and my coworkers :-)

On 7/20/11 3:19 PM, Asumu Takikawa wrote:
>* On 2011-07-17 19:13:07 +0200, Danny Wilson wrote:
*>>* Hi List,
*>>*
*>>* Short version: is there an implementation of
*>>* http://www.dwheeler.com/readable/sweet-expressions.html for
*>>* typed/racket or just racket?
*>*
*>* I've been curious about sweet expressions myself for a while
*>* too, so I went ahead and ported David Wheeler's
*>* implementation for Racket and made it a language you can use
*>* from planet.
*>*
*>* To use, write a #lang line like this:
*>*
*>* #lang asumu/sweet racket
*>*
*>* printf("Hello")
*
Cute! Thanks for the cool planet package. Here's a slightly larger
example using Redex, adapted from redex/examples/arithmetic.rkt:
#lang planet asumu/sweet racket
require rename-in(redex [term quote])
define-language lang
e n
δ1(e)
δ2(e e)
δ1 √ add1 sub1
δ2 + - * /
E hole
δ1(E)
δ2(e E)
δ2(E e)
n number
define v
reduction-relation lang
{ √(n) --> ,sqrt('n) }
{ add1(n) --> ,add1('n) }
{ sub1(n) --> ,sub1('n) }
{ +(n_1 n_2) --> ,+('n_1 'n_2) }
{ -(n_1 n_2) --> ,-('n_1 'n_2) }
{ *(n_1 n_2) --> ,*('n_1 'n_2) }
{ /(n_1 n_2) --> ,/('n_1 'n_2) }
define -->_v
context-closure v lang E
traces -->_v '-(*(√(36) /(1 2)) +(1 2))
As a thank you, I opened two tickets on planet. ;)
David