[DGD] operator+ as absolute value function?

Felix A. Croes felix at dworkin.nl
Sun May 19 22:44:46 CEST 2019


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

> I started to play with the idea of a Number object and came across an
> "I wonder if I can do that?" scenario. After writing operator- with
> varargs, I wondered if the same was possible with operator+
>
> Number m, n;
>
> m = new Number(-0.8);
> n = +m;
>
> n ==> -0.8, not 0.8
>
> I wasn't expecting 0.8 as it would be inconsistent with int and float.
> My question is if that's the whole reason, or if there is something
> more/else to consider?
>
> A second question. It seems that something like +m doesn't even go
> into operator+. Is that correct?

DGD's dialect of LPC follows C semantics for the plus sign; used with
a single argument it's not an operator but a way to force evaluation
of the argument in isolation.

For example, a + (b + c) does not actually force (b + c) to be evaluated
first; the result might be computed as (a + b) + c.  To force it, use
the plus sign:

    a + +(b + c)

What you probably want is

    n = fabs(m);

Regards,
Felix Croes


More information about the DGD mailing list