[racket] Question about string conversion

From: m0nastic at tengulabs.com (m0nastic at tengulabs.com)
Date: Thu Jul 18 02:29:30 EDT 2013

Hi, I'm super new to Racket, but had what I hope isn't too
embarrassingly easy of a question.

I'm writing a program that parses SMTP headers in order to automate some
business-y workflow. I managed to put together a series of
"regexp-match*"s to parse out the specific identifiers I was looking for
(although truth be told, mail headers are surprisingly nonstandard even
within a single message), and ran into an error later when trying to
string-append them. I eventually discovered by process of elimination
(after trying string?, etc. to figure out how the results of a regexp
are stored) that they were a list. I tried list->string and a few other
methods to covert them, but wasn't having any luck.

I eventually discovered that I could sort of cheat, by just wrapping the
regexp-match function with a car (which worked, because this particular
list only had one element), and then it was usable from then on (and
validated true from "string?").

So, my actual question is two-fold. First, It seems like I must have
missed some pretty obvious way to capture the initial regex match as a
string, but I'm not sure what it was.

And secondly, and actually what I'm more curious about, why does it
become a string when wrapped by car? I would have presumed that car
would leave structures as a list.

Again, I apologize if this is something dead-simple, but I really did
spend a good portion of the day stuck in "regex-hell", and so was
curious.

-Chris


Posted on the users mailing list.