CL-USER> (array-has-fill-pointer-p (remove-if #'oddp (make-array 10
:adjustable t :initial-contents '(0 1 2 3 4 5 6 7 8 9) :fill-pointer
0)))
T
while this is not :
CL-USER> (array-has-fill-pointer-p (remove-if #'oddp (make-array 10
:adjustable t :initial-contents '(0 1 2 3 4 5 6 7 8 9) :fill-pointer
10)))
NIL
seems to me, that when no update is done to the input sequence, it's
fine, but when remove-if updates the input vector which has
fill-pointer, the result vector does not contain fill-pointer for some
reason.
is this meant to be so - or is there any reason for it? how to do it
other way?
thank you,
karol skocik
The CLHS entry for REMOVE-IF says:
"If sequence is a vector, the result might or might not be simple,
and might or might not be identical to sequence."
So, obviously you can't rely on the result to have a fill pointer.
Cheers,
Edi.
--
Lisp is not dead, it just smells funny.
Real email: (replace (subseq "spam...@agharta.de" 5) "edi")
remove-if doesn't do anything to its argument. In general, it returns a
new sequence with the changed contents. There is no guarantee whether
the new sequence will have the same features as the input sequence, so
this means that in general, you cannot rely on the fact that the result
has, for example, a fill-pointer.
What you see happen in the first case is this: remove-if is allowed to
return its input argument when the result would be the same (equal)
anyway. Since the fill-pointer in the first case is 0, remove-if doesn't
see the elements, so by definition cannot do anything interesting. So it
just returns its input argument, which of course retains the fact that
it has a fill-pointer.
I hope this helps.
Pascal
--
2nd European Lisp and Scheme Workshop
July 26 - Glasgow, Scotland - co-located with ECOOP 2005
http://lisp-ecoop05.bknr.net/
however, i was looking to copy-seq, and it unfortunately also drops the
fill-pointer. is there any general way to make duplicates of
structures or i need to do it manually?
thank you,
karol skocik
Nope, this doesn't necessarily work either. delete-if is not required,
just allowed to change its input argument. If you want a destructive
operation, you need to do it "manually" by iterating over the array and
copying elements from old locations to new locations. sebseq and replace
may be of help, though.
> however, i was looking to copy-seq, and it unfortunately also drops the
> fill-pointer. is there any general way to make duplicates of
> structures or i need to do it manually?
A way to do what you seem to want is this:
(make-array (array-dimensions old-array)
... some properties, like fill-pointer ...
:initial-contents (loop for element across old-array
when (some-predicate-p element)
collect element))
bye
> i got it - copy-structure.
COPY-STRUCTURE copies structures, not sequences.
> but why is it not in CLTL2 by Steele? :-(
CLtL2 is not the final definition of the ANSI standard. Consult the
CLHS instead.
<http://www.lispworks.com/documentation/HyperSpec/index.html>
copy-structure doesn't copy arrays, at least not as specified by ANSI
Common Lisp.
CLtL2 describes the state of Common Lisp as of 1989. Some changes have
been made between then and the final release of ANSI Common Lisp in 1994/5.
have a nice day,
karol skocik
> Karol Skocik wrote:
>> ok, i understand now. so i need to duplicate the input sequence and put
>> is as input to delete-if, which will just alter the contents, not the
>> properties of the sequence.
>
> Nope, this doesn't necessarily work either. delete-if is not required,
> just allowed to change its input argument. If you want a destructive
> operation, you need to do it "manually" by iterating over the array
> and copying elements from old locations to new locations. sebseq and
> replace may be of help, though.
>
>> however, i was looking to copy-seq, and it unfortunately also drops the
>> fill-pointer. is there any general way to make duplicates of
>> structures or i need to do it manually?
>
> A way to do what you seem to want is this:
>
> (make-array (array-dimensions old-array)
> ... some properties, like fill-pointer ...
> :initial-contents (loop for element across old-array
> when (some-predicate-p element)
> collect element))
>
(defun copy-array (array &key copy-fill-pointer copy-adjustable
copy-displacement)
(when copy-displacement
(multiple-value-bind (disto disoff) (array-displacement array)
(when disto
(return-from copy-array
(make-array (array-dimensions array)
:element-type (array-element-type array)
:displaced-to disto
:displaced-index-offset disoff
:adjustable (when copy-adjustable
(adjustable-array-p array))
:fill-pointer (when copy-fill-pointer
(fill-pointer array)))))))
(let ((copy (make-array (array-dimensions array)
:adjustable (when copy-adjustable
(adjustable-array-p array))
:fill-pointer (when copy-fill-pointer
(fill-pointer array))
:element-type (array-element-type array))))
(dotimes (i (array-total-size copy))
(setf (row-major-aref copy i) (row-major-aref array i)))
copy))
(copy-array my-array :copy-fill-pointer t :copy-adjustable t
:copy-displacement t)
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
__Pascal Bourguignon__ http://www.informatimago.com/