From: Tamas Papp
Subject: type confusion
Date: 
Message-ID: <87ir7dotzm.fsf@pu100877.student.princeton.edu>
I want to declare that a value is an array (not necessarily simple),
one-dimensional (addressable with (aref array i)) and holds real
numbers.

;; this *x* satisfies the constraints above
CL-2D> (type-of *x*)
(SIMPLE-ARRAY DOUBLE-FLOAT (20))
;; general array type works
CL-2D> (typep *x* '(array * (*)))
T
;; but this doesn't
CL-2D> (typep *x* '(array real (*)))
NIL

I thought real was a supertype of double-float.  How can I formulate
my constraint?  It is more for SBCL to check than any optimization.

Tamas

From: Matthias Benkard
Subject: Re: type confusion
Date: 
Message-ID: <1187446365.925370.310560@50g2000hsm.googlegroups.com>
Hi,

> I want to declare that a value is an array (not necessarily simple),
> one-dimensional (addressable with (aref array i)) and holds real
> numbers.

It is not guaranteed that (make-array (list 10) :element-type 'double-
float) does not return a (SIMPLE-ARRAY T (10)), even though that is
true for SBCL.  I don't think checking the array's ARRAY-ELEMENT-TYPE
is what you want, because it is a property of the array, not of its
elements.

As a matter of fact, in SBCL, (ARRAY REAL (*)) is equivalent to (ARRAY
T (*)), which -- and this is the important point -- is not equivalent
to (ARRAY * (*)).

I hope this doesn't make matters even more confusing.  I'm not sure
how to express the problem clearly.

~ Matthias
From: Tamas Papp
Subject: Re: type confusion
Date: 
Message-ID: <87eji0pqqo.fsf@pu100877.student.princeton.edu>
Matthias Benkard <··········@gmail.com> writes:

> Hi,
>
>> I want to declare that a value is an array (not necessarily simple),
>> one-dimensional (addressable with (aref array i)) and holds real
>> numbers.
>
> It is not guaranteed that (make-array (list 10) :element-type 'double-
> float) does not return a (SIMPLE-ARRAY T (10)), even though that is
> true for SBCL.  I don't think checking the array's ARRAY-ELEMENT-TYPE
> is what you want, because it is a property of the array, not of its
> elements.
>
> As a matter of fact, in SBCL, (ARRAY REAL (*)) is equivalent to (ARRAY
> T (*)), which -- and this is the important point -- is not equivalent
> to (ARRAY * (*)).
>
> I hope this doesn't make matters even more confusing.  I'm not sure
> how to express the problem clearly.

Thanks Matthias.  Sorry for being dumb, but I would appreciate an
explanation on the difference between (ARRAY REAL (*)) and (ARRAY *
(*)).

As for the original problem, I just want to express the following:

- something is a one- (or two-) dimensional array,
- consisting of numbers on which I can perform arithmetic (real)

Tamas
From: Barry Margolin
Subject: Re: type confusion
Date: 
Message-ID: <barmar-AF9F4E.17040318082007@comcast.dca.giganews.com>
In article <··············@pu100877.student.princeton.edu>,
 Tamas Papp <······@gmail.com> wrote:

> Matthias Benkard <··········@gmail.com> writes:
> 
> > Hi,
> >
> >> I want to declare that a value is an array (not necessarily simple),
> >> one-dimensional (addressable with (aref array i)) and holds real
> >> numbers.
> >
> > It is not guaranteed that (make-array (list 10) :element-type 'double-
> > float) does not return a (SIMPLE-ARRAY T (10)), even though that is
> > true for SBCL.  I don't think checking the array's ARRAY-ELEMENT-TYPE
> > is what you want, because it is a property of the array, not of its
> > elements.
> >
> > As a matter of fact, in SBCL, (ARRAY REAL (*)) is equivalent to (ARRAY
> > T (*)), which -- and this is the important point -- is not equivalent
> > to (ARRAY * (*)).
> >
> > I hope this doesn't make matters even more confusing.  I'm not sure
> > how to express the problem clearly.
> 
> Thanks Matthias.  Sorry for being dumb, but I would appreciate an
> explanation on the difference between (ARRAY REAL (*)) and (ARRAY *
> (*)).
> 
> As for the original problem, I just want to express the following:
> 
> - something is a one- (or two-) dimensional array,
> - consisting of numbers on which I can perform arithmetic (real)

Array declarations don't allow you to say that.  When you declare the 
element type of an array, you're essentially saying that the array is 
SPECIALIZED to hold objects of only that type, not that the elements 
happen to be of that type.

This is useful for the optimizer, because specialized arrays often have 
simpler structure (the "unboxed" values are stored directly in the 
array, rather than indirectly via pointers), and the declaration allows 
it to generate code that accesses elements directly with this knowledge.  
In addition to this it may be able to propagate the type of the object 
accessed, but that's not the primary point of array declarations.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: John Thingstad
Subject: Re: type confusion
Date: 
Message-ID: <op.tw9ctrgjpqzri1@pandora.upc.no>
P� Sat, 18 Aug 2007 15:25:01 +0200, skrev Tamas Papp <······@gmail.com>:

>
> I thought real was a supertype of double-float.  How can I formulate
> my constraint?  It is more for SBCL to check than any optimization.
>
> Tamas

This is a common problem with types.
use subtypep instead.
(The uglier type is where you get portability errors because some  
implementions encode byte arrays as of type byte and soe of type bit for  
example.)