Skip to content

The - operator is not left-associative

i am trying styx by converting some d programs of mine.

i use styx v0.31.0 on debian 13.1, x86_64.

i was getting strange results from calculations done with nested loop indexes. finally i have isolated the issue and it has nothing to do with loop indexes. it seems a bug related to the - operator, but perhaps i'm missing something:

module calc3;

import std.stdio : printf = writef;

void main()
{
    printf("%d\n", 9 - 1)         ; // 8
    printf("%d\n", 9 - (1 + 3))   ; // 5
    printf("%d\n", 9 - 1 + 3)     ; // 11
    printf("%d\n", 9 + (3 - 1))   ; // 11
    printf("%d\n", 9 + 3 - 1)     ; // 11
    printf("%d\n", 9 + 3 - 1 - 2) ; // 9
}
unit calc3;

function main() {
    printf("%d\n", 9 - 1)         ; // 8
    printf("%d\n", 9 - (1 + 3))   ; // 5
    printf("%d\n", 9 - 1 + 3)     ; // 5 XXX
    printf("%d\n", 9 + (3 - 1))   ; // 11
    printf("%d\n", 9 + 3 - 1)     ; // 11
    printf("%d\n", 9 + 3 - 1 - 2) ; // 13 XXX
}

-- Marcos Cruz http://programandala.net