[plt-scheme] "raw" strings

From: Sam TH (samth at ccs.neu.edu)
Date: Fri Sep 18 19:51:16 EDT 2009

On Fri, Sep 18, 2009 at 7:21 PM, Todd O'Bryan <toddobryan at gmail.com> wrote:
> I hate to ask this, given how much I've been burned by mentioning
> experience with Python before, but...
>
> One of my favorite features of Python is the fact that you can delimit
> strings with either " or '. That way, you can enclose strings that
> have double-quotes in apostrophes and strings that have apostrophes in
> double-quotes.
>
> Clearly, this won't work with Scheme because of symbols, but another
> really nice feature of Python is the "raw" string, which is especially
> useful in things like regular expressions. Basically, a raw string
> (with the letter 'r' prepended to the front of the first quote)
> doesn't treat a backslash as a meta-character.
>
> So, if I want to match strings like 455 \ 22, 127 \ 31, or 3 \
> 5--corresponding to the regex \d+\s\\\s\d+, instead of typing
>
> "\\d+\\s\\\\\\s\\d+"
>
> I'd type
>
> r"\d+\s\\\s\d+"
>
> which is ever so much more readable.
>
> Since PLT already has #rx"patt" and #px"patt" patterns, how hard would
> it be to create a version that lets you avoid the insane amounts of
> backslash escaping?

How about

#lang at-exp scheme
(define r @regexp{\d+\s\\\s\d+})

-- 
sam th
samth at ccs.neu.edu


Posted on the users mailing list.