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

From: Neil Van Dyke (neil at neilvandyke.org)
Date: Fri Jun 3 22:58:13 EDT 2011

Carl Eastlund wrote at 06/03/2011 10:47 PM:
> To clarify this, Racket reuses the syntax of strings for regexps.  A
> regexp is first read as a string, then parsed into a regular
> expression.  So if "\d" is the same as "d" as a string, the regexp
> parser never sees the backslash.  We do not currently have a reader
> for regexps that skips this intermediate step.
>   

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.

-- 
http://www.neilvandyke.org/



Posted on the users mailing list.