From: Raymond Toy
Subject: type-of arrays with fill pointers?
Date: 
Message-ID: <4nn0t0ojc9.fsf@rtp.ericsson.se>
What is the type-of of an array with a fill-pointer?  

For example, if x is (make-array 10 :fill-pointer 3), then (type-of
x) would say (vector t 10).

Then would this make the following an error:

        (make-sequence (type-of x) (length x))

since the desired type has a length different from (length x).

To make this work, we would probably need to write

        (make-sequence (type-of x) (array-dimension x 0))

except that this is "longer" than x.

Something like

        (make-sequence (car (type-of x)) (length x))

would make a sequence of the same length as x.

Ray

From: Barry Margolin
Subject: Re: type-of arrays with fill pointers?
Date: 
Message-ID: <bpHW8.14$_w4.5015@paloalto-snr1.gtei.net>
In article <··············@rtp.ericsson.se>,
Raymond Toy  <···@rtp.ericsson.se> wrote:
>What is the type-of of an array with a fill-pointer?  

The value of the fill pointer is irrelevant to the array's type.

>For example, if x is (make-array 10 :fill-pointer 3), then (type-of
>x) would say (vector t 10).
>
>Then would this make the following an error:
>
>        (make-sequence (type-of x) (length x))
>
>since the desired type has a length different from (length x).
>
>To make this work, we would probably need to write
>
>        (make-sequence (type-of x) (array-dimension x 0))
>
>except that this is "longer" than x.

So?  Since you can change the fill pointer, you can fix it.

>Something like
>
>        (make-sequence (car (type-of x)) (length x))
>
>would make a sequence of the same length as x.

Or:

(setq new-x (make-sequence (type-of x) (array-dimension x 0)))
(setf (fill-pointer new-x) (fill-pointer x))

-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Raymond Toy
Subject: Re: type-of arrays with fill pointers?
Date: 
Message-ID: <4nit3oob8p.fsf@rtp.ericsson.se>
>>>>> "Barry" == Barry Margolin <······@genuity.net> writes:

    Barry> In article <··············@rtp.ericsson.se>,
    Barry> Raymond Toy  <···@rtp.ericsson.se> wrote:
    >> What is the type-of of an array with a fill-pointer?  

    Barry> The value of the fill pointer is irrelevant to the array's type.

Ok, that makes sense.

    >> For example, if x is (make-array 10 :fill-pointer 3), then (type-of
    >> x) would say (vector t 10).
    >> 
    >> Then would this make the following an error:
    >> 
    >> (make-sequence (type-of x) (length x))
    >> 
    >> since the desired type has a length different from (length x).
    >> 
    >> To make this work, we would probably need to write
    >> 
    >> (make-sequence (type-of x) (array-dimension x 0))
    >> 
    >> except that this is "longer" than x.

    Barry> So?  Since you can change the fill pointer, you can fix it.

    >> Something like
    >> 
    >> (make-sequence (car (type-of x)) (length x))
    >> 
    >> would make a sequence of the same length as x.

I goofed here because the resulting sequence has elements of type T
and not of the element type of x.

    Barry> Or:

    Barry> (setq new-x (make-sequence (type-of x) (array-dimension x 0)))
    Barry> (setf (fill-pointer new-x) (fill-pointer x))

But is (make-sequence '(vector t 10)) required to have a fill pointer?
At least CMUCL says it doesn't.

In any case, the question arises because I was looking at getting
CMUCL to signal errors on things like (make-sequence '(vector t 10)
4), and in some places in the code it does (make-sequence (type-of x)
(length x)) when x has a fill-pointer.  It expects the result to have
the actual length of x.  This currently works because it doesn't check
for consistent lengths.

Ray