Peculiar behaviour of 'parse'?

Started by pjot, August 12, 2004, 09:12:09 AM

Previous topic - Next topic

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

#1
127.0 is parsing as a float.

Nigel

pjot

#2
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

#3
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