[racket] Some design "whys" of regexps in Racket

From: Rodolfo Carvalho (rhcarvalho at gmail.com)
Date: Fri Jun 3 23:09:40 EDT 2011

Eli says that

(BTW, Racket's solution is something that is done in many other
> languages too.)



I come from Python where I can write

>>> re.findall("\d{2}", "06/03/2011")
['06', '03', '20', '11']

And printing the string that I used for my regexp gives:

>>> print "\d{2}"
\d{2}



That is writing strings is not exactly the same as writing "strings for a
regexp".


And then below Neil gives a plausible reason to want the syntax to be the
same.

If we are to exploit this consistency, then I see changing my head into
typing double backslashes for special regexps constructs a "price worth
paying" (given a previous background). For fresh minds, this sounds like a
very good idea.


On Fri, Jun 3, 2011 at 23:58, Neil Van Dyke <neil at neilvandyke.org> wrote:

> [...]
>
>
> Also, regexps used to be specified using strings in Racket, and still can
> be, for good reason:
>
>   (regexp (string-append "^\\d+ " (regexp-quote some-var) "$"))
>
>   #rx"^\\d+"
>
> As a programmer, getting escaping right is hard enough as it is.  You
> wouldn't want to do escaping one way for string literals and a different way
> for #rx -- that would be begging for hard-to-find bugs.



[]'s

Rodolfo Carvalho
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110604/6747d5b0/attachment.html>

Posted on the users mailing list.