Carl, yours doesn't pass the test suite. For example, you return (void) rather than 3.
I've fixed that, removed the letrec and added else support. http://github.com/jeapostrophe/exp/blob/master/cas-cad-e.rkt Jay On Sat, Oct 9, 2010 at 7:52 AM, Carl Eastlund <c...@ccs.neu.edu> wrote: > Here's my solution. It is pure (if you ignore the set! nature of > letrec), has linear expansion, avoids multiple values, and uses a > single "case" for conditional tests. The only thing it lacks that I > know of is support for "else". > > -------------------------------------------------------------------------------- > #lang racket > (require (for-syntax syntax/parse) racket/stxparam) > > (define-syntax-parameter break > (lambda (stx) (raise-syntax-error #f "used outside of cas-cad-e" stx))) > > (define-syntax cas-cad-e > (syntax-parser > [(_ e:expr [(v ...) body:expr ...+] ...) > (with-syntax ([(id ...) (generate-temporaries #'((v ...) ...))]) > (with-syntax ([(f ...) #'(start id ... finish)] > [(action ...) #'((begin) (begin body ...) ... (begin))] > [(next ...) #'(id ... finish void)]) > #'(let/ec escape > (syntax-parameterize ([break (make-rename-transformer #'escape)]) > (letrec ([f (lambda () action (next))] ...) > (case e [(v ...) (id)] ...))))))])) > > (define (nursery-rhyme n) > (cas-cad-e n > [(1 2) (displayln "buckle my shoe")] > [(3 4) (displayln "shut the door") (break)] > [(5 6) (displayln "pick up sticks")] > [(7 8) (displayln "lay them straight") (break)] > [(9 10) (displayln "a big fat hen")])) > > (for ([i '(1 2 3 4 5 6 7 8 9 10)]) > (nursery-rhyme i)) > -------------------------------------------------------------------------------- > > Carl Eastlund > -- Jay McCarthy <j...@cs.byu.edu> Assistant Professor / Brigham Young University http://teammccarthy.org/jay "The glory of God is Intelligence" - D&C 93 _________________________________________________ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users