[racket] dispatch on type
What one would want is object -> fixnum, where the fixnum identifies the
type of the object. If the fixnums are not too big, one could dispatch by
means of a vector reference.
Jos
> -----Original Message-----
> From: users-bounces at racket-lang.org
> [mailto:users-bounces at racket-lang.org] On Behalf Of Thomas Chust
> Sent: 13 June 2011 17:11
> To: Stephan Houben
> Cc: Racket Users
> Subject: Re: [racket] dispatch on type
>
> 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
> know.
>
> Ciao,
> Thomas
>
>
> --
> When C++ is your hammer, every problem looks like your thumb.
> _________________________________________________
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users