Hi, At Wed, 4 Feb 2004 09:21:49 +0900, Jamis Buck wrote: > 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. Agreed, and it seems easy to implement. > 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 > > The expression itself still returns boolean, but the object > encapsulating the flipflop is placed in 'state'. How will you use it, in other words, how and when it will be changed?
Index: node.h =================================================================== RCS file: /cvs/ruby/src/ruby/node.h,v retrieving revision 1.52 diff -u -2 -p -d -r1.52 node.h --- node.h 22 Jan 2004 08:31:33 -0000 1.52 +++ node.h 4 Feb 2004 00:53:13 -0000 @@ -327,4 +327,6 @@ typedef struct RNode { #define NEW_DOT2(b,e) NEW_NODE(NODE_DOT2,b,e,0) #define NEW_DOT3(b,e) NEW_NODE(NODE_DOT3,b,e,0) +#define NEW_FLIP2(b,e) NEW_NODE(NODE_FLIP2,b,e,local_append(internal_id())) +#define NEW_FLIP3(b,e) NEW_NODE(NODE_FLIP3,b,e,local_append(internal_id())) #define NEW_ATTRSET(a) NEW_NODE(NODE_ATTRSET,a,0,0) #define NEW_SELF() NEW_NODE(NODE_SELF,0,0,0) Index: parse.y =================================================================== RCS file: /cvs/ruby/src/ruby/parse.y,v retrieving revision 1.315 diff -u -2 -p -d -r1.315 parse.y --- parse.y 3 Feb 2004 02:23:20 -0000 1.315 +++ parse.y 4 Feb 2004 00:53:13 -0000 @@ -619,4 +619,12 @@ expr : command_call $$ = NEW_NOT(cond($2)); } + | kIN arg tDOT2 arg + { + $$ = NEW_FLIP2($2, $4); + } + | kIN arg tDOT3 arg + { + $$ = NEW_FLIP3($2, $4); + } | arg ;
-- Nobu Nakada