From: David Bakhash
Subject: diff between type and type specifier
Date: 
Message-ID: <cxjg1g0tmas.fsf@engc.bu.edu>
hi,

My question is as follows:

What is the diff between a type and a type specifier?  I know that I
can declare something to be a fixnum, but does that make `fixnum' a
type specifier?  I don't know anymore.

Basically, I was reading a Graham's book on CL, and he failed to show
fixnums as type specifiers, but did include `integer' as one.  But we
all know that telling the compiler that a variable is an "integer"
doesn't really help it very much, because it can still be a bignum or
a fixnum.  So my question is:

1) is "fixnum" a type specifier?  or just a "type"?  If the latter,
   what's the diff between the two things?
2) if I know that x is an int between 0 and 100, then what's the best
   way to declare it?

(defun f (x)
;;  (declare (type (integer 0 100) x))
;;  (declare (type fixnum x))
;;  (declare (type (fixnum 0 100) x))  ; can you even give "fixnum"
;;                                       these bounds?
  (...body of the function...))

thanks,
dave
From: Barry Margolin
Subject: Re: diff between type and type specifier
Date: 
Message-ID: <YGMr1.55$P34.807217@cam-news-reader1.bbnplanet.com>
In article <···············@engc.bu.edu>, David Bakhash  <·····@bu.edu> wrote:
>What is the diff between a type and a type specifier?  I know that I
>can declare something to be a fixnum, but does that make `fixnum' a
>type specifier?  I don't know anymore.

Here are the definitions from the CLHS:

type n. 1. a set of objects, usually with common structure, behavior, or
purpose. (Note that the expression ``X is of type Sa'' naturally implies
that ``X is of type Sb'' if Sa is a subtype of Sb.) 2. (immediately
following the name of a type) a subtype of that type. ``The type vector is
an array type.''

type specifier n. an expression that denotes a type. ``The symbol
random-state, the list (integer 3 5), the list (and list (not null)), and
the class named standard-class are type specifiers.''

Basically, a type is a conceptual thing, while a type specifier is
something that appears in a program.

>Basically, I was reading a Graham's book on CL, and he failed to show
>fixnums as type specifiers, but did include `integer' as one.  But we
>all know that telling the compiler that a variable is an "integer"
>doesn't really help it very much, because it can still be a bignum or
>a fixnum.  So my question is:
>
>1) is "fixnum" a type specifier?  or just a "type"?  If the latter,
>   what's the diff between the two things?

Section 4.2.3 of the CLHS lists all the symbols that name type specifiers.
FIXNUM is in Figure 4-2 Standardized Atomic Type Specifiers.  It sounds
like a simple omission from Graham's book.

>2) if I know that x is an int between 0 and 100, then what's the best
>   way to declare it?

(integer 0 100) or (integer (0) (100)) depending on whether the limits are
inclusive or exclusive.  Any decent implementation should be able to
recognize that this should be implemented using FIXNUM.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.