grammarware / software-evolution

Software Evolution
MIT License
1 stars 0 forks source link

Examples of contracted expression for EVALUATE and WHEN #18

Open ypj0202 opened 5 months ago

ypj0202 commented 5 months ago

If I understand correctly, for EVALUATE clause and contracted expression for that it should support the following: For regular EVALUATE:

EVALUATE X + 1 ALSO Y + 2
    WHEN X < 10 ALSO Y > 2
        blablabla
       ........

For contracted expression

EVALUATE X + (10 / 2)
    WHEN 10 
        blablabla
        WHEN > 20
                blablabla
        ....

My questions:

1) Is my intuition for the logic of EVALUATE right? 2) How should I deal in case of the following:

EVALUATE X = 1 ALSO Y = 10
    WHEN 1 ALSO 2
        blablabla
       .....

Also, the example you give in another discussion:

EVALUATE X ALSO Y
    WHEN 10 ALSO "FOO"
        DISPLAY "FOO10"
    WHEN 20 ALSO "BAR"
        DISPLAY "BAR20"
    WHEN OTHER
        DISPLAY "NO"
END
grammarware commented 5 months ago

If I understand it correctly, you might be overthinking it. EVALUATE just matches one expression given in its header with one expression given in the WHEN clause (or two or more, one by one, in case of ALSO).

So if you start with EVALUATE X + 1 ALSO Y + 2, both expressions evaluate to two decimals, so you should also match them with two decimals. For instance, WHEN 10 ALSO 42, without any mentioning of Xs and Ys.

Conversely, when you do EVALUATE X = 1 ALSO Y = 10, both are Booleans, so inside this block there should be things like WHEN TRUE ALSO FALSE.

Another idiomatic commonly encountered pattern in real COBOL code is EVALUATE TRUE which allows you to basically collect together any kinds of Boolean expressions in different WHENs of the same EVALUATE. That's where you go WHEN X>10 and WHEN Y < 0, etc.

You don't need to worry about contracted expressions here.

ypj0202 commented 5 months ago

Ah, that makes sense. Now I am wondering what are you expecting for the contracted expression of EVALUATE and WHEN?