Question on (parse ...

For the Compleat Fan
Locked
jsmall
Posts: 26
Joined: Mon Sep 20, 2004 1:44 am

Question on (parse ...

Post by jsmall »

If I try to parse:

Code: Select all

   > (parse "Hello    World" {\s+} 0)
   ("Hello" "World")

;; it works!  And

   > (parse "" {\s+} 0)
   ()

;; it also works.  But then

   > (parse "    "  {\s+} 0)
   ("" "")

;; Is this right?  I want to get back an empty list.

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

Post by Lutz »

This is correct behaviour, 'parse' shows leading and trailing empty fields around separators. This gets clear when showing a CSV parsing example:

(parse "one,two,three" ",") => ("one" "two" "three")

but:

(parse "one,two,three," ",") => ("one" "two" "three" "")

the trailing comma before the end of the record suggests, that there is an empty field between the comma end end of the record. Sometimes you have sequences with empty fields like:

(parse "1,2,,,5" ",") => ("1" "2" "" "" "6")

now the case you demonstrated, but with a comman separator instead:

(parse "," ",") => ("" "")

There are two empty fields separated by a comma

Lutz

Locked