On 11/23/05, Damian Conway <[EMAIL PROTECTED]> wrote: > Luke wrote: > > > On 11/22/05, Damian Conway <[EMAIL PROTECTED]> wrote: > > > >> :syntax<POSIX> > >> :syntax<grep> > >> :syntax<egrep> > >> :syntax<vim> > >> :syntax<Snobol> > >> :syntax<Google> > > > > > > Aren't we providing an interface to define your own regex modifiers? > > Sure. But it'd lead to much less namespace pollution and much greater > readability if there were only one standard modifier that subsumed all future > possibilities.
Okay, I don't think this is an important part of the design of the language, so I'll not fuss over it. However, I think it's a good case study that covers some important issues. Something I've learned from Haskell: if you have the following three things: * Fine-grained control over your lexical environment * A compiler that tells you when you're referring to something ambiguously, rather than just having one symbol hide the other * A way in all cases to refer to an export that you have *not* imported, using some fully-qualified form Then namespace pollution is not an issue... at all. I don't believe we have the last of those for regex modifiers. We should get it. Now, by grouping all these different modules under a standard :syntax, the following things follow: * The string has to be evaluated at compile-time; i.e. $syn = "vim"; rx:syntax($syn)/.../ is not legal. It takes a fair amount of maturity in the workings of Perl to understand why that doesn't work. * Various :syntax modifiers will probably do very different things inside the regex (one approach is not likely to work for everyone), so our common interface will add little to nothing over the standard modifier interface, other than another name to sift through in the docs. * We have to provide our own registry for these, which map strings onto implementations, rather than using the already existing symbol table. By reinventing this registry, we lose fully-qualified referrability to these symbols, which was one of the requirements for avoiding namespace pollution. It seems we've made that problem worse... but see below: :-) * The :syntax modifiers cannot take arguments, further worsening the namespace pollution problem rather than helping it. Or... if they can take arguments, it would be like this: :syntax['POSIX', :charclasses], which means reinventing the calling conventions already in place in much of the language (and losing some features in the process of reinventing, as usual), and losing any type information in the process. Also it's butt ugly. So... those have some strong language in there. I don't really want to go back and sugar them up, but pretend I did. Anyway, I think the biggest point is that when you substitute a string for a first-class object, you have to emulate (poorly) all the fancy mechanisms that the language designers have meticulously crafted. Luke