Page 1 of 1

element-type in array..

Posted: Fri Oct 26, 2012 1:05 pm
by megera
HI
If I try to make a resizable string with make-array, but error raises with vector-push..:

Code: Select all

(defparameter str (make-array 10 :fill-pointer 0 :adjustable t :element-type 'character))
>STR
(vector-push 'a' str)   ;;error raise:

value STR is not of the expected type (AND
                                       ARRAY
                                       (SATISFIES
                                        ARRAY-HAS-FILL-POINTER-P)).
   [Condition of type TYPE-ERROR]
....?it works without specify :element-type.....but why it's atype error?? 'a' is a char...
thanks in advance!!!

Re: element-type in array..

Posted: Fri Oct 26, 2012 2:16 pm
by Goheeca
Because 'a' isn't a character. This works:

Code: Select all

(vector-push #\a str)

Re: element-type in array..

Posted: Fri Oct 26, 2012 2:22 pm
by Paul
(vector-push 'a' str) is the same as (vector-push 'a 'str) is the same as (vector-push (quote a) (quote str)) -- you're trying to push the symbol A onto the symbol STR.

You probably want VECTOR-PUSH-EXTEND, too.

Re: element-type in array..

Posted: Sat Oct 27, 2012 1:29 am
by megera
opss'!!!
perfect thanks!