"Mark J. Reed" <[EMAIL PROTECTED]> writes: > On 2003-11-25 at 18:17:04, Piers Cawley wrote: >> aString replace: aPattern with: aString. >> >> aString replaceAll: aPattern with: aString. > > Stop! Stop that at once! No small talk; we're here for > serious discussions! > > :) > >> Except... the second argument isn't strictly a string because it's >> evaluated in the match context. Assuming we get a pure functional form >> of the substitution operator, then scoping's going to be fun. If you >> want a simple form with the signature: >> >> method String::sub( Rule $pattern, String $replacement ) >> >> you're almost certainly going to have to implement that as a macro so >> you can get at the string before it's interpolated. > > Or you could have the method version take a closure/proc > object/block/whatever, which gets run each time to generate the > replacement. Quoting is then not an issue.
Well, yes, sorry, thought that was implicit. The macro form would simply replace itself with an appropriate call to the method String::sub(Rule $pattern, Block &replace_block) {...} form. This is perl after all, no harm sprinkling a little syntactic sugar. Catch is, the macro form can't really (safely) look like a method call because at macro expansion time we don't know the invocant's type (or even if it is an object). > Hm. What was that about the Rubyometer? :) Is that how Ruby does it then?