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

From: Eli Barzilay (eli at barzilay.org)
Date: Sat Jun 4 11:38:32 EDT 2011

An hour and a half ago, Rodolfo Carvalho wrote:
> On Sat, Jun 4, 2011 at 10:30, Hendrik Boom <hendrik at topoi.pooq.com> wrote:
> 
> > On Fri, Jun 03, 2011 at 11:40:37PM -0400, Eli Barzilay wrote:
> > >
> > >   >>> print "\"
> > >   [SyntaxError: ...]   <-- surprise
> >
> > Just curious: what happens with
> >
> > >>> print "\""
> >
> > >>> "\""
> '"'
> 
> The internal double quote is escaped by the backslash.
> The result is just another way to write the same without need to escape:
> 
> '"'
> 
> (single, double, single quote)
> 
> 
> And if you "print" it, you get:
> 
> >>> print "\""
> "
> 
> 
> If I am not wrong, it is the same as Racket, except for the
> representation that the prompt spits out for "\" " .  Although
> Python's motto is "There should be one-- and preferably only one
> --obvious way to do it. <http://www.python.org/dev/peps/pep-0020/>",
> the language itself does one thing in two different ways, there are
> actually more than 2 ways to represent that string.

Much more:

1. "\""
2. '"'
3. '\"'
4. """\""""
5. '''\"'''
6. r'"'
7. r'''"'''

The missing thing here is r"..." because I don't see a way to write
that string using it.

> You see some more "inconsistency" if you try to represent a single quote as
> string:
> 
> >>> "'"
> "'"
> 
> This time the internal representation of the string uses " instead of '.

This part actually makes sense -- have the printed representation
choose the convenient syntax.  Racket has this too with symbols (due
to lisp legacy):

  -> 'a\bc
  'abc
  -> '|abc|
  'abc
  -> '|a b|
  '|a b|
  -> 'a\ b
  '|a b|

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!


Posted on the users mailing list.