[racket] dispatch on type

From: Thomas Chust (chust at web.de)
Date: Mon Jun 13 11:11:03 EDT 2011

2011/6/13 Stephan Houben <stephanh at planet.nl>:
> [...]
> I have code like this which dispatches on
> the type of a homogenous vector:
> [...]
> I was wondering if there is a more efficient way to
> do this, one which doesn't involve a linear scan
> over all possible types. I presume that at the C level
> there is a "type tag" associated with any of these types;
> is it possible to access this from the Racket level?
> [...]

Hello Stephan,

since everything can be interpreted as a structure in Racket, one
thing you could do is dispatch on the name of structure types:

  (define (identify v)
    (case (vector-ref (struct->vector v) 0)
      ((struct:byte-string) "bytes")
      ((struct:u16vector) "small words")
      (else "whatever")))

However, whether this will really result in a performance gain I don't


When C++ is your hammer, every problem looks like your thumb.

Posted on the users mailing list.