Hi Michael,

On 2014-10-24 17:55:24 +0000, Michael Bernstein wrote:
>    Proposed Racket version (based on the Erlang example)
>    uses #:where keyword:
>    (define/match (insert X lst)
>      [{ X '() }                          (list X)]
>      [{ X (cons H T) } #:where (<= X H)  (list* X H T)]
>      [{ X (cons H T) }                   (cons H (insert X T))])
>    (define (insertion-sort lst)
>      (foldl insert '() lst))

You can write this as:

  (define/match (insert X lst)
    [{ X '() }                          (list X)]
    [{ X (cons H T) } #:when (<= X H)   (list* X H T)]
    [{ X (cons H T) }                   (cons H (insert X T))])
  (define (insertion-sort lst)
    (foldl insert '() lst))

Note that #:where is replaced by #:when. I believe this works in Racket
v6.0 and later.

Cheers,
Asumu
_________________________
  Racket Developers list:
  http://lists.racket-lang.org/dev

Reply via email to