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
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.
>>>>> "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