puss in a string bug?

Notices and updates
Locked
Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

puss in a string bug?

Post by Dmi »

Code: Select all

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
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Re: puss in a string bug?

Post by rickyboy »

Dmi wrote:

Code: Select all

> (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
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

Post by Dmi »

:-) Yes, thanks Rick!

But now I have another issue:

Code: Select all

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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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

Code: Select all

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

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

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

Code: Select all

(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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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

Code: Select all

(set 'a '(a b c))
(push '- a 3)
a => (a b c -)
its ok on lists but broken on strings

Lutz

Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

Post by Dmi »

Also the reverse situation exists:

Code: Select all

> (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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

Post by Dmi »

Thanks, Lutz!

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

Locked