Page 1 of 1

Peculiar behaviour of 'parse'?

Posted: Thu Aug 12, 2004 4:12 pm
by pjot
Hi Lutz,

This may be an obvious issue, but anyway:

-----------------

#!/usr/bin/newlisp
#
# Testing the 'parse' instruction
#
(set 'var (parse "Lutz Mueller created newlisp 127.0.0.1"))
(println var)
(exit)

-----------------

Now, the result of this program is:

("Lutz" "Mueller" "created" "newlisp" "127.0" ".0" ".1")

It strikes me that the IP address is splitted as well. The documentation mentions that "...when no str-break is given, parse tokenizes according newLISP's internal parse rules." However, it seems logical to expect something like the following, using space as splitter:

("Lutz" "Mueller" "created" "newlisp" "127.0.0.1")

Can you clarify in this situation the internal parse rule? I am using newLisp 8.1.0 on Slackware 9.1 Linux.

Thanx,

Peter

Posted: Thu Aug 12, 2004 5:11 pm
by nigelbrown
127.0 is parsing as a float.
Nigel

Posted: Thu Aug 12, 2004 5:18 pm
by pjot
OK, I figured that, but I didn't expect it since it seems not so consequent: the first part of the string is parsed as string, using whitespace as separator; the second part as float, obviously depending on the contents of that last part of the string.

The 'parse' command is probably more intelligent than I expected it to be... (When the str-break is defined as " ", the parse works as expected.)

Posted: Thu Aug 12, 2004 11:14 pm
by Lutz
When using 'parse' without the last parameter you get the newLISP source code parser. Remember too, that you can put regular expression patterns into the break-string for more complex parseing behaviour.

Lutz