[plt-scheme] Papers on criticism of Scheme?

From: Alex Shinn (alexshinn at gmail.com)
Date: Mon Nov 3 01:59:04 EST 2008

Stephen Bloch <sbloch at adelphi.edu> writes:

> I have a bunch of students right now trying to write
>
> (define (scale-posn num (make-posn x y))
>    (make-posn (* num x) (* num y)))
>
> which actually does make sense, but isn't legal Scheme.  Any
> likelihood of a Haskell language module coming for DrScheme?  Or a
> Scheme dialect with pattern-matching in function headers?

The most common match syntax in use is based on an old
library by Andrew Wright.  There's a portable hygienic
version with many extensions available at

  http://synthcode.com/scheme/match.scm

The MATCH-LAMBDA* syntax it provides is close to what you
want, but could be made a little more convenient with
something like:

  (define-syntax define*
    (syntax-rules ()
      ((def (name params ...) body ...)
       (define name (match-lambda* ((params ...) body ...))))
      ((def name value)
       (define name value))))

Then you can do

  (define* (scale-posn num ($ posn x y))
    (make-posn (* num x) (* num y)))

This is using the (non-portable, but widely supported) $
record syntax.  PLT's new default match uses a different
syntax closer to what you want, and is extensible.  It would
be easy to provide a DEFINE-RECORD-TYPE constructor which
automatically provided the MAKE-FOO match pattern for a
record FOO.  The example would then become

  (define* (scale-posn num (make-posn x y))
    (make-posn (* num x) (* num y)))

exactly as you wrote.

-- 
Alex


Posted on the users mailing list.