[DGD] Arithmetic with objects and int/float

Felix A. Croes felix at dworkin.nl
Sat May 4 11:36:14 CEST 2019


nikoroleva <natasha.i.koroleva at gmail.com> wrote:

>[...]
> Another question has more to do with the arithmetic. With the +
> operator implemented in the rational object type, I can do r + i where
> r is the rational object and i is an int. Mathematically, I should
> just as well be able to do i + r. Is it worthwhile writing code to
> enable such an expression? How would you do it?
>
> I started to explore this idea using a number object type that can be
> an int, float, castable string, or rational object. Personally and so
> far, I don't find it worth much more than scratching a curiosity itch.
> But I'm happy to hear your thoughts on these things.

You are discovering problems which have standard solutions in
popular programming languages.  Java has an Integer class so that
operations like Integer + Rational can be made to work.  It also has
an abstract Number class, which can be implemented by Integer.

In LPC this has only been an option since the introduction of
light-weight objects, which DGD provides but which are absent in other
dialects.  And the uptake of light-weight objects by MUD programmers
has been slow.

I had planned to introduce such classes to the Cloud library, but
due to too many projects and too many other things which are also
important for the Cloud library (such as Strings with full Unicode
support, a full HTTP 1.1 + TLS implementation, a HTTP 2.0
implementation, a QUIC implementation, etc) this little project has
languished.

Regards,
Felix Croes


More information about the DGD mailing list