Peculiar behaviour of 'parse'?

Q&A's, tips, howto's
Locked
pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Peculiar behaviour of 'parse'?

Post 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

nigelbrown
Posts: 429
Joined: Tue Nov 11, 2003 2:11 am
Location: Brisbane, Australia

Post by nigelbrown »

127.0 is parsing as a float.
Nigel

pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post 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.)

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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

Locked