From: Markus Date: 2004-10-08T05:18:59+09:00 Subject: Bug in free-form operator patch Shoot. It doesn't correctly distinguish multiple user-defined operators on one class. I know what the problem is, and tonight I'll try to figure out how to fix it. -- Markus On Thu, 2004-10-07 at 12:18, Markus wrote: > !!! -> <- -- +++ -=- */* !! ~~~ <=..< .... > > > * Have you ever wanted to define your own operators in ruby? > > * Have you ever wanted to play around with experimental hash or > range semantics, but wanted a concise syntax for the > constructors? > > * Are you crazy enough to install a compiler patch from someone > WHO OPENLY ADMITS TO NOT KNOW C? (for those of you that need > everything quantified, that's a metric craziness index of about > 0.6 Why) > > If you answered yes to all of the above, have I got a patch for you. > > ---------------------------------------------------------------- > > As mentioned previously, I've been working on a patch that would let you > write things like: > > class Pair > attr_accessor :l,:r > def initialize(l,r) > @l,@r = l,r > end > end > > class Object > def -->(other) > Pair.new(self,other) > end > end > > print 1-->5,"\n" > > This is the pre-alpha release of that patch. Basically, any sequence > of "operator characters" that isn't otherwise used is now user > definable, though you are warned to use spaces where this would be > ambiguous (e.g. x+=-1). > > In this version, the operators are always binary, non-associative, > and mid-precedence. I can see how to let the users set the precedence, > but can not figure out what "scope" the precedence declarations should > have. I can NOT see how it could depend on the class of the recipient, > which would be in some ways idea and in others hideous. > > Several of you have expressed interest in this; let me know if you > try it out & what you think. Bug reports are especially welcome. > > -- Markus > > ---------------------------------------------------------------- > > Normally try to preface code I post with some sort of warning about > the quality/soundness of the code I'm posting. In this case, though, my > C skills aren't up to rating my code here. To me, it is much easier to > read (albeit in theory microscopically slower) than the way C is usually > written. Native speakers of C will doubtlessly be scandalized by my > accent. > > So the best I can do is say, 1) it works on my machine, 2) I > haven't been able to measure any performance impact, 3) it doesn't seem > to break anything that I know of, though it does generate some warnings > (by design) on existing scripts that run operators together (e.g. > x+=-1). > > I am NOT using this in a production environment, nor would I > recommend any else do so. But it's fun to play with. >