From: Jim Weirich Date: 2004-10-09T12:59:40+09:00 Subject: Re: ANN: Free-form-operators patch Markus wrote: > This is a very good description of why I'm unsure about letting the > user set the precedence/associativity/arity. Do you mind if I use it? Please do! > I'm being a bit more conservative at this point: only characters > that are already found in ruby operators (and only on combinations that > are not already used) may be user defined. Hmmm ... I felt my position was the conservative one :-) I think yours will be quite hard on the programmer. Quick, without looking ahead ... which of the following operators can appear in valid ruby code today ... (A) <-+ (B) +/- (C) !~~ (D) ++ I'll comment on something else (to provide spoiler prevention :-) >>[...] User defined Binary operators should >>be the same as the highest precedence binary operator under the unary >>operators. > > Why the highest? I know that's how eiffel does it, but I don't > recall the rational. I've also considered some function of the length > or contents (such that the built in operators would "fit" the scheme), > but I haven't found anything I like. I'm not strongly tied to it being the highest. Whatever it is, it should be easy to remember. I don't want to have to remember 35 levels of operator precedence (I can go back to C++ if I want that). So highest seems like an easy to remember option. If you have another easy to remember scheme, I would be open to it. Now back to the legal operators ... (A) is legal, e.g. 2<-+1 => false (B) is illegal, e.g. 2+/-1 => illegal, however, 2/-1 is legal (C) is illegal (but I'm not sure why) ! ~~1 is legal, but !~~1 gives strange results try: ruby -e '!~~1' and see for yourself. (D) is legal, e.g. ++1 => 1 Anyways, I'm not sure it will be immediately obvious to the casual observer that +/- is a user defined operator and ++ and <+- are concatenations of existing legal Ruby built in operators. (Or that !~~ looks like a concatentation of built in operators, but for some reason is not). -- -- Jim Weirich jim@weirichhouse.org http://onestepback.org ----------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)