From: Bulent Murtezaoglu
Subject: array dimension guaranteed to be a fixnum?
Date: 
Message-ID: <87n22dpf8p.fsf@kapi.internal>
The hyperspec tells me that the array dimensions should be fixnums>=0.
I also checked the function array-dimension, this time the hyperspec says
it returns an integer.  Is this an oversight or am I missing something?  
I got curious about that when I discovered in code like

(dotimes (j (array-dimension foo 0))
    (do-something))	

j needed a fixnum declaration for the implicit increment operation to
be open coded.  I thought this was due to insufficient type-inference
on ACL, but apparently the hyperspec does not sanction what I was
after.  (I don't imagine the standard itself is different).  

???

BM



 

From: Howard R. Stearns
Subject: Re: array dimension guaranteed to be a fixnum?
Date: 
Message-ID: <36CADD94.D0977E0B@elwood.com>
Bulent Murtezaoglu wrote:
> 
> The hyperspec tells me that the array dimensions should be fixnums>=0.
> I also checked the function array-dimension, this time the hyperspec says
> it returns an integer.  Is this an oversight or am I missing something?
> I got curious about that when I discovered in code like
> 
> (dotimes (j (array-dimension foo 0))
>     (do-something))
> 
> j needed a fixnum declaration for the implicit increment operation to
> be open coded.  I thought this was due to insufficient type-inference
> on ACL, but apparently the hyperspec does not sanction what I was
> after.  (I don't imagine the standard itself is different).
> 
> ???
> 
> BM
> 

I think you're safe with the fixnum declaration.  Saying that something
is an integer is not inconsistent with saying that it is a fixnum, so
the spec isn't wrong.  Furthermore, the spec says:

  1.5.1.4.1 Resolution of Apparent Conflicts in Exceptional Situations

  If more than one passage in this specification appears to apply to the
same   
  situation but in conflicting ways, the
  passage that appears to describe the situation in the most specific
way (not 
  necessarily the passage that provides
  the most constrained kind of error detection) takes precedence. 

By the way, I personally prefer to deftype my own mnemonic types like
INDEX, which provides more perspicuous documentation when used as a
declaration than FIXNUM.  

Furthermore, I would prefer to have INDEX be defined as `(integer 0
,most-positive-fixnum) than as simply FIXNUM, so that the compiler can,
in principle tell me if I've accidentally made it negative somehow. 
Unfortunately, CMUCL is the only Lisp implementation I know of that can
make good use of such a specific definition.  I believe that ACL
actually generates worse code for (integer 0 268435455) than it does for
fixnum.  (But then, that's another advantage of using the deftype -- the
value can be conditionally defined for different platforms.)

There is one weakness of using the deftype:  Because there is no
EXPAND-DEFTYPE function, many (compiler-)macros are written which
specicifically check for declarations that are FIXNUM, but not things
which are subtypes. (LOOP is a likely culprit.)  In principle, this can
be fixed in implementations that properly implement SUBTYPEP, by having
the (compiler-)macro expansion code check declarations using SUBTYPEP. 
Unfortunately, some implementations have a pretty week (non-ANSI)
SUBTYPEP.  In practice, though, I don't think this comes up too often,
and using the deftype should be good practice.  (Anyone have any counter
experience?)
From: Duane Rettig
Subject: Re: array dimension guaranteed to be a fixnum?
Date: 
Message-ID: <490dxx8s9.fsf@beta.franz.com>
"Howard R. Stearns" <······@elwood.com> writes:

> By the way, I personally prefer to deftype my own mnemonic types like
> INDEX, which provides more perspicuous documentation when used as a
> declaration than FIXNUM.  

I agree.

> Furthermore, I would prefer to have INDEX be defined as `(integer 0
> ,most-positive-fixnum) than as simply FIXNUM, so that the compiler can,
> in principle tell me if I've accidentally made it negative somehow. 

Yes, but `(integer 0 ,array-dimension-limit) would be more appropriate.

> Unfortunately, CMUCL is the only Lisp implementation I know of that can
> make good use of such a specific definition.  I believe that ACL
> actually generates worse code for (integer 0 268435455) than it does for

Worse?  Do you mean bigger, or slower, or both?  Examples, please?

> fixnum.  (But then, that's another advantage of using the deftype -- the
> value can be conditionally defined for different platforms.)

-- 
Duane Rettig          Franz Inc.            http://www.franz.com/ (www)
1995 University Ave Suite 275  Berkeley, CA 94704
Phone: (510) 548-3600; FAX: (510) 548-8253   ·····@Franz.COM (internet)
From: Howard R. Stearns
Subject: Re: array dimension guaranteed to be a fixnum?
Date: 
Message-ID: <36CB4CA8.8F589045@elwood.com>
Duane Rettig wrote:
> 
> "Howard R. Stearns" <······@elwood.com> writes:
> 
> > By the way, I personally prefer to deftype my own mnemonic types like
> > INDEX, which provides more perspicuous documentation when used as a
> > declaration than FIXNUM.
> 
> I agree.
> 
> > Furthermore, I would prefer to have INDEX be defined as `(integer 0
> > ,most-positive-fixnum) than as simply FIXNUM, so that the compiler can,
> > in principle tell me if I've accidentally made it negative somehow.
> 
> Yes, but `(integer 0 ,array-dimension-limit) would be more appropriate.
> 
> > Unfortunately, CMUCL is the only Lisp implementation I know of that can
> > make good use of such a specific definition.  I believe that ACL
> > actually generates worse code for (integer 0 268435455) than it does for
> 
> Worse?  Do you mean bigger, or slower, or both?  Examples, please?

Sorry, I should really know better than to be so sloppy.  I want to
answer right away, and I don't have time to work up a complete example
(wimp!) but my recollection is that ACL failed to use inlined machine
instructions when using a declaration of the form (integer ... ...)
which hapend to be a subtypep of fixnum, even though the same code did
use inlined machine instructions when FIXNUM was explicitly given.  I
think the example was within LOOP, but I'm not sure.

(For the record and as penence, let me say that ACL does a MUCH better
job of generating efficient code then Eclipse, which doesn't currently
respect type declarations at all!)

> 
> > fixnum.  (But then, that's another advantage of using the deftype -- the
> > value can be conditionally defined for different platforms.)
> 
> --
> Duane Rettig          Franz Inc.            http://www.franz.com/ (www)
> 1995 University Ave Suite 275  Berkeley, CA 94704
> Phone: (510) 548-3600; FAX: (510) 548-8253   ·····@Franz.COM (internet)