[plt-scheme] (typeof obj)

From: Jos Koot (jos.koot at telefonica.net)
Date: Mon Jun 11 00:55:38 EDT 2007

----- Original Message ----- 
  From: YC 
  To: Jos Koot ; PLT Scheme List ; Robert Nikander 
  Sent: Monday, June 11, 2007 12:47 AM
  Subject: Re: [plt-scheme] (typeof obj)

  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. 
I am not sure whether or not Scheme *does know* THE type of a value. I am sure the PLT team has more knowledge of that. My way of looking at it is that there are predicates that know whether or not a value satisfies them. Furthermore there is the question how far you want to go in specifying the type. Is a list of numbers simply a list or is it 'a list of numbers'? The number of predicates you may think of is unlimited.
Jos Koot

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070611/2df38a5c/attachment.html>

Posted on the users mailing list.