newLISP Fan Club

Forum => newLISP newS => Topic started by: Dmi on July 09, 2007, 06:59:19 AM

Title: puss in a string bug?
Post by: Dmi on July 09, 2007, 06:59:19 AM
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...
Title: Re: puss in a string bug?
Post by: rickyboy on July 09, 2007, 07:22:13 AM
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)?
Title:
Post by: Dmi on July 09, 2007, 07:32:43 AM
:-) 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"
>
Title:
Post by: Lutz on July 09, 2007, 07:50:12 AM
-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



in the first paragraph



Lutz
Title:
Post by: cormullion on July 09, 2007, 08:10:03 AM
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

Title:
Post by: Lutz on July 09, 2007, 09:54:52 AM
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
Title:
Post by: Dmi on July 10, 2007, 06:48:59 AM
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...
Title:
Post by: Lutz on July 10, 2007, 07:57:02 AM
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
Title:
Post by: Dmi on July 10, 2007, 03:05:13 PM
Thanks, Lutz!



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