From: Eric Mahurin Date: 2005-10-14T00:04:02+09:00 Subject: Re: Default argument values for blocks --- Christophe Grandsire wrote: > Selon Eric Mahurin : > > > > > Anybody ever just consider making a new expression (or > maybe > > RHS?) rule just for these default values such that "|" was > not > > in this expression? (...) in this or-less expression would > > still use the normal expression. Wouldn't this solve the > > problem? You'd just be forced to use (...) whenever you > wanted > > to "|". That doesn't seem so bad. > > > > ... { |a,b=1|2|a*b } # b default: 1, code: 2|a*b > > ... { |a,b=(1|2)|a*b } # b default: (1|2), code: a*b > > ... { |a,b=1+2|a*b } # b default: 1+2, code: a*b > > > > I don't see any ambiguity doing it this way. > > > > Yacc does. Even the simple { |a,b=1| a*b } fails because Yacc > treats it as { | > a,b=(1| a*b) }. And that *cannot* be solved in the current > state of Yacc. The > problem is that there doesn't seem to be *any* solution that > solves both this > problem and the problem of allowing bitwise or's in default > arguments, short of > renaming the bitwise or, which would be such a compatibility > break that it isn't > worth contemplating. > > This is at least my understanding of the problem. Are you saying this from experience? It sounds like it, but your last statement says not. Don't be so authoritative if you are not. Take a look at the parse.y code. Look at the "arg" rule. That's where the action is. All I'm suggesting is that this entire rule be duplicated and renamed (and all immediate recursive calls to itself). Maybe "arg2". And then in this new rule, this alternative would be deleted: | arg '|' arg { /*%%%*/ $$ = call_op($1, '|', 1, $3); /*% $$ = dispatch3(binary, $1, ID2SYM('!'), $3); %*/ } Then in the new block args definition, you'd allow optional arguments (something like f_opt) which would call this "arg2" instead of "arg". When I get a chance, I might try this. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com