Damian wrote: > Debbie Pickett asked: > > So my question is: why two words for regular expressions, but only one > > for subroutines? Are "rule" and "rx" just alternate spellings, much as > > Perl5's "for" and "foreach" are? If so, why the two keywords? > > If not, why not? > They are not quite synonyms. C<rule> allows a name and an argument list > and requires braces as delimiters: > rule config_line { <ident> = \N* } > rule config_line ($ident) { <$ident> = \N* } > $config_line = rule { <ident> = \N* } > $config_line = rule ($ident) { <$ident> = \N* } > C<rx> is purely anonymous (doesn't allow a name), doesn't allow arguments, > but can take (nearly) any delimiters you like: > $config_line = rx/ <ident> = \N* /; > $config_line = rx{ <ident> = \N* }; > $config_line = rx[ <ident> = \N* ]; > $config_line = rx« <ident> = \N* »; > # etc. > So the "real" name is C<rule>, and C<rx> is just a convenient short-hand.
So . . correct me if I'm wrong . . . C<rule> allows us to define both named and anonymous rules, depending on context. C<rx> allows us to define only anonymous rules. C<rule> is the more general one, and you can use it exclusively if that's what you feel like. The only extra piece of syntactic sugar that C<rx> is giving us over C<rule>[*] is the ability to have arbitrary delimiters. If I were satisfied with always using C<{}> as delimiters for C<rx> then a program would run the same if I did a C<s:each/rx/rule/> on it. Now . . . Is there some _syntactic_ constraint (i.e., required by the parser) that requires C<rule> to use braces for delimiters? That is, shouldn't the following: $config_line = rule ($ident) { <$ident> = \N* } always be parseable for any given value of C<{> and C<}> (barring obvious exceptions like colons and parentheses)? Or, to put it more succinctly: do there exist two pieces of *syntactically correct* code like ... rule ... and ... rx ... (where the ... are identical in both) which each produce *valid* and *different* semantics? To me, that'd be the only reason for C<rx> and C<rule> to be different keywords. [**] Especially since we're making such a big deal about patterns and subroutines having lots of parallels. The same parallel doesn't exist for subroutines[***]; why should it for pattern matching? [*] Note that I'm not talking about what C<rule> gives us over C<rx>; that's a different issue. [**] As opposed to C<rx> and C<rule> being two different spellings of the same keyword, something I don't object to. [***] Notwithstanding C<< -> >>, which I now understand to be nothing more than a different spelling of C<sub>. See above footnote. -- Debbie Pickett http://www.csse.monash.edu.au/~debbiep [EMAIL PROTECTED] "Don't think sorry's easily said. Don't try turning tables instead. You've taken lots of chances before, but I ain't gonna give any more. That's how it goes, 'cause part of me knows what you're thinking." - _Eye in the Sky_, APP