[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: benefits of SRE syntax
-----BEGIN PGP SIGNED MESSAGE-----
Michael Montague writes:
> Maybe I am being a heretic, but what are the benefits of the SRE syntax?
It reflects the tree-like structure of regular expressions as a
data type. What you're calling the "traditional syntax" flattens that
structure into a linear string, which the reader has to parse in order to
recover the structure.
The SRE syntax also supports modular design and component reuse
better than the traditional syntax. Scheme's built-in binding mechanisms
can be used to give names to useful and interesting subexpressions. Such
subexpressions can be tested independently. The traditional syntax fails
in all these respects, because the only intuitive way to combine regular
expressions in that syntax is by string concatenation, which is error-prone
(particularly, but not exclusively, when there are submatch assignments)
and comparatively inflexible.
> The beginning of the rational notes that "regular expressions are the
> lingua franca of string matching today". Part of that lingua franca is
> the traditional syntax of regular expressions.
Yes, it's a sad story. If the tool-builders who implemented Unix
had thought carefully about the traditions relating to regular expressions
that the designers of SNOBOL4 had already tried to establish, we wouldn't
find it necessary to reinvent them every few years. One weeps to think of
all the agonizing, needless labor that programmers have done over the years
in trying to understand and debug regular expressions in traditional
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.9 <http://mailcrypt.sourceforge.net/>
-----END PGP SIGNATURE-----