In article <40203AC3.4010207 / email.byu.edu>, Jamis Buck <jgb3 / email.byu.edu> wrote: >Phil Tomson wrote: > >> >>Another idea would be to have a 'from (condition) to (condition)' >>statement that looks looks like: >> from l=~/BEGIN/ to l=~/END/ do >> #do something in this range >> end >> >> > >What if we just use the keyword 'in' to introduce a flipflop, and retain >the range-ish syntax to separate the conditions? Something like this: > > if in l=~/BEGIN/ .. l=~/END/ > ... > end > >The advantage of using a boolean phrase is that you can use it in >conditions, where it is most common. That also lets you do something >when the flipflop is false, which the 'from..do' construct you suggested >doesn't (easily) allow. > >Since getting at the object that encapsulates the state of the flipflop >will be less common (one might even say "rare", although its hard to say >at this point since neither Perl nor Ruby allow it), the common case >(just getting the boolean result) should be simple and straightforward. >Getting at the object might be done via something like this: > > in l=~/BEGIN/ .. l=~/END/ => state <snip> > >>I'm just sort of brainstorming here, but I think the 'from .. to .. >>{}' statement is very readable and the intent is quite clear and it >>just might be able to replace the current flipflop operators. >> >> > >I agree, 'from .. to ...' is very readable, but perhaps not as >convenient given the regular usage of the flip-flop operator. Then >again, I'd like to hear from someone who uses the flip-flop a lot as to >whether they feel it would be cumbersome. Readability is good, but if >you take it too far you get VB and Pascal, which are easy to learn, but >clunky (IMO) to actually write software in. I use the flip-flop pretty commonly when I'm parsing files. For my usage, the from..to.. would probably work fine: #not a real example, of course File.foreach{|l| from l=~/BEGIN/ to /END/ do #nesting should work ok from l=~/def/ to /end/ do #method definition end from l=~/from/ to /end/ do #proposed syntax, parse thyself end end #would we need elsfrom? from l=~/<html>/i to l=~/</\html>/i #in an HTML file end } But others have suggested that they use the flipflop for other things. I think that if the from construct returns a FlipFLop object that it would be useable for these other appliations as well, but I'd like to hear some other suggestions. Maybe the from..to.. construct should just return a boolean, then it would be used with an if statement like: if from (condition) to (condition) But using 'from' could still be slanted more toward the file parsing application, rather than a more general purpose usage. I thought of 'from' because that's the main way I use the flip/flop operator. BTW: I really don't like the 'flip' idea: if flip (condition) to (condition) because it's not clear from reading it what 'flip' means. Phil