x - y block: no drawer

Request a new command, feature, or improvement

Moderator: MSandro

Post Reply
SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

x - y block: no drawer

Post by SimpleSi » Sep 18th, '17, 20:23

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

JohnM
Posts: 379
Joined: Sep 11th, '15, 14:42

Re: x - y block: no drawer

Post by JohnM » Sep 20th, '17, 12:11

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.

SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

Re: x - y block: no drawer

Post by SimpleSi » Sep 20th, '17, 13:50

Fair enough :)

Post Reply