Page 1 of 1

x - y block: no drawer

Posted: Sep 18th, '17, 20:23
by SimpleSi
the X-Y block doesn't have a drawer like + and * and I've now got used to having one :)

The x / y doesn't have one either but its going to be a rare event to want to use one so not too bothered about that
Simon

Re: x - y block: no drawer

Posted: Sep 20th, '17, 12:11
by JohnM
Yes, that's intentional.

Addition and multiplication are "associative", meaning that you can apply the operations in any order and get the same result. That is:

(a + b) + c equals a + (b + c)

The same is not true of subtraction or multiplication:

a - (b - c) is not the same as (a - b) - c

Of course, we could adopt a convention, such as left-to-right associativity, but then people would need to know or guess that rule. That's harder for newcomers to GP, and even experts might sometimes misread such code. I would rather have the grouping be made explicit by the programmer, a practice I follow myself in every programming language I use, even if the language doesn't require it.

Note that if you want:

(((a - b) - c) - d) - ...

then you can use:

a - (+ b c d ...)

which is only one extra block.

Re: x - y block: no drawer

Posted: Sep 20th, '17, 13:50
by SimpleSi
Fair enough :)