[plt-scheme] (typeof obj)

From: Jos Koot (jos.koot at telefonica.net)
Date: Sun Jun 10 13:14:46 EDT 2007

----- 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
> 



Posted on the users mailing list.