Re: foperator overloading (was Re:fraclib.e)
- Posted by jbrown1050 at hotpop.com Jan 23, 2003
- 372 views
On Wed, Jan 22, 2003 at 11:28:59PM +0000, Pete Lomax wrote: > > Someone, I forget who, wrote: Me. :T > > >> BTW, what would be really useful here, is a way to make a custom type > >> which allows one to redefine the math operators, so I could do "f1 + f2" > >> rather than "f_add(f1, f2)", but have the 2 mean the same thing. > > Interesting. The syntax should(could) be something as trivial as: > > include custom_type_redefine.e -- global redefine() > > function f_add(blah, > blah, > blah > end function > > -- <no difference to normal yet> > > type ftype(blah... > redefine("+","f_add") > ... > end type > > ... > ... > .. > > Somehow I realise there is true potential here, but a convincing > example escapes me (hint, hint) Perhaps for natural-looking OOP? (obj.method becomes call_method(obj, method), and obj:var becomes getvar(obj, var), for example ...) > > Pete > PS as "+" is both a unary and binary operator, you might have to > redefine({"+",2},{"f_add",2}). Other stuff too. Actually, my parser, which is based on Dot, doesn't use a function, it adds a new keyword, newoperator. Example: newoperator % remainder 2 Tells it to replace all "x % y" with "remainder(x , y)". (The last parameter is the number of parameters the function takes, which is either 1 or 2.) This works easily for all things, except '=', and slicing. operator [] slice 1 operator .. multi_slice 2 I hacked my rewriter to be able to handling slicing, so s["1"] becomes slice(s, "1") and s[1.."3"] becomes multi_slice(s, 1, "3"), for example. However, my parser currently has a problem with '=', as its both assignment and comparison operator. Still working on fixing that. jbrown > > ==^^=============================================================== > This email was sent to: jbrown1050 at hotpop.com > > > TOPICA - Start your own email discussion group. FREE! -- /"\ ASCII ribbon | \ / campain against | Linux User:190064 X HTML in e-mail and | Linux Machine:84163 /*\ news, and unneeded MIME |