element-type in array..

Discussion of Common Lisp
Post Reply
megera
Posts: 30
Joined: Wed Oct 10, 2012 1:34 pm

element-type in array..

Post by megera » Fri Oct 26, 2012 1:05 pm

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!!!

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: element-type in array..

Post by Goheeca » Fri Oct 26, 2012 2:16 pm

Because 'a' isn't a character. This works:

Code: Select all

(vector-push #\a str)
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

Paul
Posts: 106
Joined: Tue Jun 02, 2009 6:00 am

Re: element-type in array..

Post by Paul » Fri Oct 26, 2012 2:22 pm

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

megera
Posts: 30
Joined: Wed Oct 10, 2012 1:34 pm

Re: element-type in array..

Post by megera » Sat Oct 27, 2012 1:29 am

opss'!!!
perfect thanks!

Post Reply