element-type in array..

Discussion of Common Lisp

element-type in array..

Postby 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!!!
megera
 
Posts: 30
Joined: Wed Oct 10, 2012 1:34 pm

Re: element-type in array..

Postby 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).
User avatar
Goheeca
 
Posts: 197
Joined: Thu May 10, 2012 12:54 pm

Re: element-type in array..

Postby 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.
Paul
 
Posts: 106
Joined: Tue Jun 02, 2009 6:00 am

Re: element-type in array..

Postby megera » Sat Oct 27, 2012 1:29 am

opss'!!!
perfect thanks!
megera
 
Posts: 30
Joined: Wed Oct 10, 2012 1:34 pm


Return to Common Lisp

Who is online

Users browsing this forum: Google [Bot] and 0 guests

cron