puss in a string bug?

Started by Dmi, July 09, 2007, 06:59:19 AM

Previous topic - Next topic

Dmi

dmi@stone:~$ newlisp
newLISP v.9.1.7 on Linux, execute 'newlisp -h' for more info.

> (set 'a "abc")
"abc"
> (push "-" a -1)
"-"
> a
"abc-"                       ;right
> (set 'a "abc")
"abc"
> (push "-" a -2)
"-"
> a
"ab-c"                      ;right
> (set 'a "abc")
"abc"
> (push "-" a -3)
"-"
> (set 'a "abc")
"abc"                       ;wrong
> (set 'a "abcd")
"abcd"
> (push "-" a -3)
"-"
> a
"ab-cd"                    ;right
> > (set 'a "abc")
"abc"
> (push "-" a -4)
"-"
> a
"-abc"                     ;right
>

Locale is ru_RU.KOI8-R (single byte).



I suspect that that this is something like unicode tricks...
WBR, Dmi

rickyboy

#1
Quote from: "Dmi"> (set 'a "abc")
"abc"
> (push "-" a -3)
"-"
> (set 'a "abc")
"abc"                       ;wrong


I don't see how this could be wrong.  Maybe you are missing a step?  Like showing the value of a after (push "-" a -3)?
(λx. x x) (λx. x x)

Dmi

#2
:-) Yes, thanks Rick!



But now I have another issue:
dmi@stone:~$ newlisp
newLISP v.9.1.7 on Linux, execute 'newlisp -h' for more info.

> (set 'a "abc")
"abc"
> (push "-" a -3)
"-"
> a
"-abc"
> (set 'a "abc")
"abc"
> (push "-" a -2)
"-"
> a
"ab-c"   ; I think should be "a-bc"
>
WBR, Dmi

Lutz

#3
-1 is for the last position, -2 for the scond last etc.



if the position is greater than the length of the string it will go always at the beginning:



> (set 'a "abc") (push "-" a -1) a
"abc"
"-"
"abc-"
> (set 'a "abc") (push "-" a -2) a
"abc"
"-"
"ab-c"
> (set 'a "abc") (push "-" a -3) a
"abc"
"-"
"-abc"
> (set 'a "abc") (push "-" a -4) a
"abc"
"-"
"-abc"
>


only on arrays overshooting the index will given an error message, on strings it will just go to the first or last position.



See here:



http://newlisp.org/newlisp_manual.html#indexing">http://newlisp.org/newlisp_manual.html#indexing



in the first paragraph



Lutz

cormullion

#4
It does look, though, as if one is missing: where is "a-bc" on the way up?


(for (i -5 5 )
(set 'a "abc")
(push "-" a i)
(map print (list i "t" a "n")))

-5 -abc
-4 -abc
-3 -abc
-2 ab-c
-1 abc-
0 -abc
1 a-bc
2 ab-c
3 ab-c
4 ab-c
5 ab-c


Lutz

#5
yes, it should but it at the and if the index is greater or equal the length like in:


(set 'a '(a b c))
(push '- a 3)
a => (a b c -)


its ok on lists but broken on strings



Lutz

Dmi

#6
Also the reverse situation exists:
> (set 'a "abc")
"abc"
> (push "-" a 3)
"-"
> a
"ab-c"
> (set 'a "abc")
"abc"
> (push "-" a 1)
"-"
> a
"a-bc"

I.e. we can't push to the end of the string. But we can into a list...
WBR, Dmi

Lutz

#7
Thanks Dmitry, I looked into it yesterday and its all fixed in 9.1.9.



If this is an urgent issue for you or anybody else than contact me with a private message and I make 9.1.9 available to you. I didn't make a development release yet because still want to integrate the GUI-server code into it, adapt the scripts for making binary releases and haven't done any testing of the new utf-8 file-and-directory name handling in Win32. So at the moment its only good for UNIX/Mac OX X. 9.1.9 will be ready either this weekend or coming week (including binary releases for Win32 and MacOS X.



Lutz

Dmi

#8
Thanks, Lutz!



This waits for me. My companion programmer has stuck onto it, but now we made a workaround.
WBR, Dmi