[racket] TR Structure Matching

From: Asumu Takikawa (asumu at ccs.neu.edu)
Date: Tue Dec 4 18:06:33 EST 2012

On 2012-12-04 17:53:57 -0500, Ray Racine wrote:
>    How does one bind an identifier to the matched structure?

You can use an `and` pattern. In your example:

  (define js (Person "Joe" "Smith"))

  (: do-it (Thing -> String))
  (define (do-it thing)
    (match thing
      ;; shadow `thing` here
      ((and [Person fn ln] thing)
       (displayln fn)
       (person-name thing))))

  (do-it js)

Cheers,
Asumu

Posted on the users mailing list.