[plt-scheme] Objects, classes and match

From: Sam TH (samth at ccs.neu.edu)
Date: Fri Oct 3 09:16:54 EDT 2008

On Fri, Oct 3, 2008 at 8:12 AM, Dave Gurnell <d.j.gurnell at gmail.com> wrote:
> Hi all,
>
> Is there any way to use match on an object? I can't see anything in the docs
> (although I may be missing something obvious). Something like:
>
>    (match (new my-class%)
>      [(struct my-class% (a b c))
>      ...])
>
> I don't mind setting up a custom match-expander. I suppose I could convert
> the object to a vector and match on that. That doesn't seem like a
> particularly efficient solution, though.

There isn't anything in match at the moment for this.  If I was
implementing this, I'd probably want this to do something like:

(class [a x] [b y] [c z]) => (app (lambda (e) (list (send e a) (send e
b) (send e c))) (list x y z))

maybe using `get-field' instead of `send'.

If you have other ideas for the API, I'm happy to hear them.  I
haven't found anything I particularly like, and that's why there's
nothing in `match' at the moment.

Thanks,
-- 
sam th
samth at ccs.neu.edu


Posted on the users mailing list.