From: Ladv�nszky K�roly
Subject: type-of in Scheme
Date: 
Message-ID: <04d6a72ee1f67c582c4150505209b2ce@news.meganetnews.com>
Is there a function in Scheme (Petite Chez) that returns the type of its
argument like Lisp's TYPE-OF does?
Thanks,

K�roly

From: William D Clinger
Subject: Re: type-of in Scheme
Date: 
Message-ID: <fb74251e.0312011747.6a4ee130@posting.google.com>
"Ladv�nszky K�roly" <··@bb.cc> asked:
> Is there a function in Scheme (Petite Chez) that returns the type of its
> argument like Lisp's TYPE-OF does?

Not in Scheme, and probably not in Petite Chez.  Scheme doesn't
have the CL equivalent of type specifiers either.  You might try
returning the type predicates themselves in lieu of type specifiers,
but then would (TYPE-OF 14) return EXACT? or INTEGER? ?

Is a puzzlement.

Will
From: Kaz Kylheku
Subject: Re: type-of in Scheme
Date: 
Message-ID: <cf333042.0312051217.4a89c2f0@posting.google.com>
··········@verizon.net (William D Clinger) wrote in message news:<····························@posting.google.com>...
> "Ladv�nszky K�roly" <··@bb.cc> asked:
> > Is there a function in Scheme (Petite Chez) that returns the type of its
> > argument like Lisp's TYPE-OF does?
> 
> Not in Scheme, and probably not in Petite Chez.  Scheme doesn't
> have the CL equivalent of type specifiers either.  You might try
> returning the type predicates themselves in lieu of type specifiers,
> but then would (TYPE-OF 14) return EXACT? or INTEGER? ?

It would return the most specific indicator that applies to the given
instance, of course. The same way that the CL (TYPE-OF 14) returns
FIXNUM or BIGNUM, rather than RATIONAL or even INTEGER.
From: Kalle Olavi Niemitalo
Subject: Re: type-of in Scheme
Date: 
Message-ID: <87he0eygbi.fsf@Astalo.kon.iki.fi>
···@ashi.footprints.net (Kaz Kylheku) writes:

> The same way that the CL (TYPE-OF 14) returns FIXNUM or BIGNUM,
> rather than RATIONAL or even INTEGER.

Actually, FIXNUM is specified to be a supertype of (signed-byte
16), so (type-of 14) must not return BIGNUM.  It can however
return a more specific type such as (integer 10 15).  Returning a
corresponding predicate in Scheme would get rather pointless, though.
From: Kent M Pitman
Subject: Re: type-of in Scheme
Date: 
Message-ID: <sfw4qwe91t9.fsf@shell01.TheWorld.com>
Kalle Olavi Niemitalo <···@iki.fi> writes:

> ···@ashi.footprints.net (Kaz Kylheku) writes:
> 
> > The same way that the CL (TYPE-OF 14) returns FIXNUM or BIGNUM,
> > rather than RATIONAL or even INTEGER.
> 
> Actually, FIXNUM is specified to be a supertype of (signed-byte
> 16), so (type-of 14) must not return BIGNUM.  It can however
> return a more specific type such as (integer 10 15).  Returning a
> corresponding predicate in Scheme would get rather pointless, though.

Btw, as a related matter of history, during the time of CLTL, I got a
query from some maker of a Lisp for, I believe, some CDC machine,
where they made the decision to only have one general representation
of integers, so that everything was effectively a BIGNUM.  I don't
think they had what they thought of as a FIXNUM type.  The guy
contacting me wanted to know whether he could make
MOST-POSITIVE-FIXNUM be NIL (which I didn't think was a good idea).  

I think in ANSI CL, the answer would be to have fixnums only, and to
have BIGNUM be type-equal to the class NIL in that bizarre case, since
BIGNUM and FIXNUM form an exhaustive partition of the class INTEGER and
the set of fixnums is required to be non-empty and I don't otherwise see
where you'd draw the line.  I _suppose_ you could just draw it at some
arbitrary place and confuse everyone by so doing.

The lingering problem if you don't draw an arbitrary line is what you
put in MOST-POSITIVE-FIXNUM if you have only one representation type
because I think to be truly conforming you have to fill half of your
memory with the most positive integer you can make in that space
(reserving the other half of your memory for the most negative integer
you can make)...

I guess there's mostly still a presupposition in ANSI CL that there
will be two distinct representations, though there's no actual verbiage
directly requiring it.

Design can be such fun.
From: Ray Dillinger
Subject: Re: type-of in Scheme
Date: 
Message-ID: <3FD141BC.C34E4C40@sonic.net>
Kent M Pitman wrote:
>
> I guess there's mostly still a presupposition in ANSI CL that there
> will be two distinct representations, though there's no actual verbiage
> directly requiring it.
> 
> Design can be such fun.

I would be surprised if that were the case, actually; I'm elbows-deep 
in a compiler now and I have four different representations for integers.
I'm using hardware fixnums of 32 and 64 bits, then unsegmented bignums 
where the entire number is dynamically allocated and collected as a unit, 
and segmented bignums, where the numbers are represented as a potentially 
non-contiguous list of chunks.  

64-bit integers reduce the number of bignums that have to be allocated
outside their call frames by about 80%, which means I get to spend 
less time garbage collecting.  Adding them was an efficiency win. 
Unsegmented bignums are fine for almost everything else, but if they 
get too huge, working with them can choke the garbage collector I'm 
using so there's the segemented representation.  I'm less sure that 
this was a win, though; if I can fix the garbage collector to work 
better with big chunks and do on-demand compacting, then the segmented 
representation will come out.

			Bear
From: Thomas A. Russ
Subject: Re: type-of in Scheme
Date: 
Message-ID: <ymiy8tnte51.fsf@sevak.isi.edu>
Kent M Pitman <······@nhplace.com> writes:

> The lingering problem if you don't draw an arbitrary line is what you
> put in MOST-POSITIVE-FIXNUM if you have only one representation type
> because I think to be truly conforming you have to fill half of your
> memory with the most positive integer you can make in that space
> (reserving the other half of your memory for the most negative integer
> you can make)...

Wouldn't you only need to use 1/3 of your space?  With most-positive and
most-negative fixnum constants taking up 2/3 of the space, that leaves
you just enough workin memory to make another fixnum that is the size of
one of the biggest ones....

:)

-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Christophe Rhodes
Subject: Re: type-of in Scheme
Date: 
Message-ID: <sqhe0eqab4.fsf@lambda.jcn.srcf.net>
···@ashi.footprints.net (Kaz Kylheku) writes:

> ··········@verizon.net (William D Clinger) wrote in message news:<····························@posting.google.com>...
>> "Ladv�nszky K�roly" <··@bb.cc> asked:
>> > Is there a function in Scheme (Petite Chez) that returns the type of its
>> > argument like Lisp's TYPE-OF does?
>> 
>> Not in Scheme, and probably not in Petite Chez.  Scheme doesn't
>> have the CL equivalent of type specifiers either.  You might try
>> returning the type predicates themselves in lieu of type specifiers,
>> but then would (TYPE-OF 14) return EXACT? or INTEGER? ?
>
> It would return the most specific indicator that applies to the given
> instance, of course. The same way that the CL (TYPE-OF 14) returns
> FIXNUM or BIGNUM, rather than RATIONAL or even INTEGER.

In addition to Kalle's point about (type-of 14) not being allowed to
return BIGNUM, I should also like to point out that FIXNUM is
similarly not allowed as the return value.  14 is typep UNSIGNED-BYTE,
which is one of the ANSI specified types, so consequently (type-of 14)
must return a type that is a subtype both of FIXNUM and of
UNSIGNED-BYTE; for instance: (INTEGER 0 536870911) on a 32-bit lisp
with 30-bit fixnums.

Christophe
-- 
http://www-jcsu.jesus.cam.ac.uk/~csr21/       +44 1223 510 299/+44 7729 383 757
(set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b)))
(defvar b "~&Just another Lisp hacker~%")    (pprint #36rJesusCollegeCambridge)
From: Kalle Olavi Niemitalo
Subject: Re: type-of in Scheme
Date: 
Message-ID: <87llppdffq.fsf@Astalo.kon.iki.fi>
Christophe Rhodes <·····@cam.ac.uk> writes:

> In addition to Kalle's point about (type-of 14) not being allowed to
> return BIGNUM, I should also like to point out that FIXNUM is
> similarly not allowed as the return value.

Hmm, then there is a bug in the CLHS example about TYPE-OF, as it
offers FIXNUM as a possible result of (type-of (expt 2 40)).

Is there a public list of known (but not necessarily verified by
the committee) errata somewhere?
From: Jens Axel Søgaard
Subject: Re: type-of in Scheme
Date: 
Message-ID: <3fcb8b59$0$70004$edfadb0f@dread12.news.tele.dk>
Ladv�nszky K�roly wrote:
> Is there a function in Scheme (Petite Chez) that returns the type of its
> argument like Lisp's TYPE-OF does?

I don't think so, but I don't know for sure.

You will probably recieve better answers in comp.lang.scheme.

-- 
Jens Axel S�gaard