[plt-scheme] (typeof obj)

From: YC (yinso.chen at gmail.com)
Date: Sun Jun 10 18:47:04 EDT 2007

This is something I wonder as well... given that internally Scheme *does
know* about the type of a value, why isn't there a function that expose the
information?  Type-based dispatching is after all a legitimate development
technique.

Thanks,
yinso

On 6/10/07, Jos Koot <jos.koot at telefonica.net> wrote:
>
>
> ----- Original Message -----
> From: "Robert Nikander" <nikander at nc.rr.com>
> To: "PLT Scheme List" <plt-scheme at list.cs.brown.edu>
> Sent: Sunday, June 10, 2007 6:28 PM
> Subject: [plt-scheme] (typeof obj)
>
>
> > Is there a way to get a type-name symbol or type object for any  scheme
> > object?
>
> Of course there is a way, but you may not like it:
>
> (define (types-of x) (filter identity (map (lambda (predicate typename)
> (and
> (predicate x) type-name)) predicates type-names)))
> (define predicates (list integer? procedure?, etc)
> (define type-names '(integer procedure, etc))
>
> Of course the procedure returns a list of types, for a 1 is an integer, a
> rational, a real and a complex number.
> You also can think of adapting procedure make-struct-type, such as to add
> their
> predicates and names to the lists.
> Same for define-struct, let-struct ...
> Same for classes.
>
> If you want only one type returned in stead of a list, two conditions must
> be
> met:
> First: for every two types A and B either A and B disjunct or A a subset
> of B or
> B a subset of A.
> Second: carefully compose the lists of predicates and their names.
> Jos Koot
>
> >
> > (type 1) => 'integer
> >
> > or
> >
> > (type 1) => #<type integer>
> > (type (type x)) => #<type type>
> >
> >
> > Rob
> > _________________________________________________
> >  For list-related administrative tasks:
> >  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> >
>
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070610/b97c6d31/attachment.html>

Posted on the users mailing list.