Re: Re: Operator overloading

"Charles Patterson" <cpatterson-N2D8602I6TJWk0Htik3J/[email protected]> Mon, 17 Mar 2003 10:51:09 -0500
Newsgroups gmane.comp.lang.moto.devel
Message-ID <003901c2ec9d$0a0b79a0$8b14a8c0@cpatterson>
> > We want to let programmers overload:

> > + (arg1, arg2)
> > += (arg1, arg2)
> > ...
> > [] (arg1, arg2) set

> I think initially this set is fine. I might also add 'eq' and 'ne' to
> the list as a way of overloading Object equality

Playing the devil's advocate, if this were C++, this set would be a great
start.  You could overload mathematical operators for types like Matrix,
Vector, and Complex.  However, I don't expect lots of Moto programs to need
these types or mathematical operators much, since Moto is initially a
web-oriented language.  If this is an experiment for "internal use"
essentially, then great.  Otherwise, see below.

> > [ Question: will it be possible in the future to let the programmer
> > overload
> > whatever operator and even new ones (those that are not actually
> > handled by
> > moto)? What changes would be needed in moto.y and moto.l? ]
> >
> I don't believe it would be possible to let extension authors overload
> operators that aren't specifically parsed by moto.l and moto.y . There
> is an idea of 'mixins' I've seen in some other languages but I'm not
> sure if those are such a good idea.

Before locking in a plan for overloading operators, if Moto wants to be the
ultimate embeddable language, starting with the web, I think handling
*operators* defined externally would be a huge benefit and really push Moto
as a unique tool!  That is, Moto becomes efficient and pleasurable to
program in each embedding environment.  I'm not just saying that it should
handle external functions.  It could handle external "infix" functions and
"keywords," etc.  (Probably including overloading these functions.)  I
imagine this relates to overloading because it would require similar syntax
and Moto internal changes.  (You could think of defining new operators and
keywords as "overloading" otherwise null functions?  You'd still need the
ability to define and declare operators just like overloading does.)

The example that comes to mind, would be the ability to define "scope" for
the web:

    // Several keywords have been defined now
    page int success;    // success will leave scope after this page is
processed
    session String account;    // account is defined for this user's entire
session
    site int loginErrors;    // loginErrors is defined for the entire site.

Look how easy it would be to use a site-wide var then?

    lockedAccounts++;

Woohoo!  In reality, the new keywords -- page, session, and site -- would be
some kind of wrapper around an Object declaration.  The internals of the
function would promote() or what have you.

I could try to create more examples (and better examples), but the web is
such a rich environment that it isn't hard to imagine the use of such a
thing.  The web is a mixture of GUI programming, logic programming, and
stateless programming, etc.  It provides no real support for any of these.
I think the trend of embedded languages that provide no more than some logic
programming (reasonable database access) aren't all that useful.  I think
sites have already reached a size where they are not maintainable because
the tools required too much work (and by programmers who weren't prepared
for it).  There could be much "syntactic sugar" applied.

Later,
Charlie