push on strings

Q&A's, tips, howto's
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

push on strings

Post by newdep »

Hi Lutz,


> (setq t "")
""
> (push "a" t 0)
"a"
> t
"a"
> (push "b" t 1)
"b"
> t
"ba"
> (push "c" t 2)
"c"
> t
"bca"
>
> (push "d" t 3)
"d"
> t
"bcda"
>


This is odd...Why is "c" at position 1 and "d" at position 2?

This is only possible if the string-index does not start at 0
(as lists do start at 0, this is confusing..)

but thats not the case ->

> (setq t "")
""
> (length t)
0
> (push "a" t)
"a"
> (length t)
1
> (t 0)
"a"
>



Norman.
-- (define? (Cornflakes))

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

It is confusing when the length to push is bigger then the string itself, then we
have to deal with an exeption.. a round-robbin counter in this case...
-- (define? (Cornflakes))

Locked