Re: [svn:perl6-synopsis] r8899 - doc/trunk/design/syn
On Fri, Apr 21, 2006 at 03:15:12PM -0400, Uri Guttman wrote: : oy! the habits to be broken and relearned! Habits are no fun unless they're either good or bad. Larry
Re: [svn:perl6-synopsis] r8899 - doc/trunk/design/syn
> "JSD" == Jonathan Scott Duff <[EMAIL PROTECTED]> writes: JSD> On Fri, Apr 21, 2006 at 11:06:20AM -0700, Larry Wall wrote: >> On Fri, Apr 21, 2006 at 12:45:13PM -0500, Jonathan Scott Duff wrote: >> : According to S05, "a /.../ matches immediately in a value context >> : (void, Boolean, string, or numeric)" and since >> : >> : (state $x) ||= / pattern /; >> : >> : is very much the same as >> : >> : state $x; $x = $x || /pattern/; >> : >> : I'd say that's a "boolean context" and thus matches against $_ instead >> : of assigning the Regex object to $x. >> >> Except the right side of || isn't in boolean context till you evaluate >> $x that way, so it probably wants to be written with m//: JSD> I almost added a little bit of text to the end of that other message JSD> but didn't. I think it's most appropriate now: JSD> I must say that I have trouble distinguishing when using // gives you JSD> a Regex object and when it actually does pattern matching, so I intend JSD> on always using m// when I want a match, and some form of rx// when I JSD> want an object. having read S05's take on that i agree in general. i will probably always use rx// the way you had to use qr// in p5. i may drop the m in // as that is the classic 'match this now'. but i think it is good style to mark these as to what you mean and not let the DWIM rule for you. but then i also rarely use $_ in p5 so i would be using ~~ as i use =~ now and that always means match so the m wouldn't be needed for clarification. but the way p6 uses $_ in some places is much better than p5 so that rule may need changing too. oy! the habits to be broken and relearned! uri -- Uri Guttman -- [EMAIL PROTECTED] http://www.stemsystems.com --Perl Consulting, Stem Development, Systems Architecture, Design and Coding- Search or Offer Perl Jobs http://jobs.perl.org
Re: [svn:perl6-synopsis] r8899 - doc/trunk/design/syn
On Fri, Apr 21, 2006 at 11:06:20AM -0700, Larry Wall wrote: > On Fri, Apr 21, 2006 at 12:45:13PM -0500, Jonathan Scott Duff wrote: > : According to S05, "a /.../ matches immediately in a value context > : (void, Boolean, string, or numeric)" and since > : > : (state $x) ||= / pattern /; > : > : is very much the same as > : > : state $x; $x = $x || /pattern/; > : > : I'd say that's a "boolean context" and thus matches against $_ instead > : of assigning the Regex object to $x. > > Except the right side of || isn't in boolean context till you evaluate > $x that way, so it probably wants to be written with m//: I almost added a little bit of text to the end of that other message but didn't. I think it's most appropriate now: I must say that I have trouble distinguishing when using // gives you a Regex object and when it actually does pattern matching, so I intend on always using m// when I want a match, and some form of rx// when I want an object. -Scott -- Jonathan Scott Duff [EMAIL PROTECTED]
Re: [svn:perl6-synopsis] r8899 - doc/trunk/design/syn
On Fri, Apr 21, 2006 at 12:45:13PM -0500, Jonathan Scott Duff wrote: : According to S05, "a /.../ matches immediately in a value context : (void, Boolean, string, or numeric)" and since : : (state $x) ||= / pattern /; : : is very much the same as : : state $x; $x = $x || /pattern/; : : I'd say that's a "boolean context" and thus matches against $_ instead : of assigning the Regex object to $x. Except the right side of || isn't in boolean context till you evaluate $x that way, so it probably wants to be written with m//: state $x; $x = $x || m/pattern/; to force the match immediately. Also, the emulation of ?...? is not complete without actually evaluating $x, so this might be clearer: $result = do { state $x ||= m/pattern/ } or maybe even $result = do { state $x ||= m/pattern/; $x } though of course that's redundant since the ||= returns its current value. Larry
Re: [svn:perl6-synopsis] r8899 - doc/trunk/design/syn
On Fri, Apr 21, 2006 at 01:12:35PM -0400, Uri Guttman wrote: > > "a" == autrijus <[EMAIL PROTECTED]> writes: > > a> * S05: Oops, turns out I entirely read perlop.pod incorrectly; > a> "it matches once only" means "it matches successfully once only", > a> not "it performs the match once only". Sorry, TimToady++'s > a> original example of: > > a> (state $x) ||= / pattern /; > > a> was correct. > > a> +To reset the pattern, simply say C<$x = 0>. > > i did a fresh read of S05 due to all the recent activity (i will post > some edits and questions soonish), but that example baffles me. how does > it emulate the (never used by me) // of p5? my take would be that the rx > would be or-assigned to $x and it would remain set through repeated > calls to the outer sub (assuming a sub). what is the context that makes > it match against $_ vs returning an rx. According to S05, "a /.../ matches immediately in a value context (void, Boolean, string, or numeric)" and since (state $x) ||= / pattern /; is very much the same as state $x; $x = $x || /pattern/; I'd say that's a "boolean context" and thus matches against $_ instead of assigning the Regex object to $x. -Scott -- Jonathan Scott Duff [EMAIL PROTECTED]
Re: [svn:perl6-synopsis] r8899 - doc/trunk/design/syn
> "a" == autrijus <[EMAIL PROTECTED]> writes: a> * S05: Oops, turns out I entirely read perlop.pod incorrectly; a> "it matches once only" means "it matches successfully once only", a> not "it performs the match once only". Sorry, TimToady++'s a> original example of: a> (state $x) ||= / pattern /; a> was correct. a> +To reset the pattern, simply say C<$x = 0>. i did a fresh read of S05 due to all the recent activity (i will post some edits and questions soonish), but that example baffles me. how does it emulate the (never used by me) // of p5? my take would be that the rx would be or-assigned to $x and it would remain set through repeated calls to the outer sub (assuming a sub). what is the context that makes it match against $_ vs returning an rx. wouldn't the assignment bleed into the the //? or is $x || /pattern/ going to do a match if it $x is false? in any case, one quick comment on S05 is it needs some more examples and some explanations of how the examples do what they are claimed to do. i know this is a synopsis/spec but some places do go into more explanation with examples than others. i would like to see it more consistant at that level. thanx, uri -- Uri Guttman -- [EMAIL PROTECTED] http://www.stemsystems.com --Perl Consulting, Stem Development, Systems Architecture, Design and Coding- Search or Offer Perl Jobs http://jobs.perl.org