Re: lex behavior
Brent Dax asked: > Will that handle captures correctly? I believe so. Each (successful) time through the loop we cache a reference to the candidate's match object, which will successfully have stored all the captures from the candidate's matching. Then we reinstate the best candidate, by binding it to $0. Hence the best candidate (with its stored captures) becomes the "official" match of the rule. > Maybe you should temporize $0... $0 is lexical to each regex/rule. No need to temporize. Damian
Re: lex behavior
On Thu, Jun 13, 2002 at 03:48:25PM -0700, Larry Wall wrote: > But the most straightforward way to match longest is probably to use > :any to get a superposition of matches, and then pull out the longest > match. So, does :any return a list of the substrings that matched or a list of match objects? Or some polymorhpic thing that can be either? Would something like this work? rule max ($pat) { $0 := { reduce { length $^a > length $^b ?? $^a :: $^b } <:a $pat>; } } "bacamus" =~ m//; -Scott -- Jonathan Scott Duff [EMAIL PROTECTED]
Re: lex behavior
On Fri, 14 Jun 2002, Jonathan Scott Duff wrote: : On Thu, Jun 13, 2002 at 03:48:25PM -0700, Larry Wall wrote: : > But the most straightforward way to match longest is probably to use : > :any to get a superposition of matches, and then pull out the longest : > match. : : So, does :any return a list of the substrings that matched or a list : of match objects? Or some polymorhpic thing that can be either? : Would something like this work? : : rule max ($pat) { : $0 := { : reduce { length $^a > length $^b ?? $^a :: $^b } <:a $pat>; : } : } : : "bacamus" =~ m//; Yeah, something like that. Could well be a longest() builtin, or close-to-builtin, of course. Larry