ml4ai / automates

AutoMATES: Automated Model Assembly from Text, Equations, and Software
https://ml4ai.github.io/automates
Other
25 stars 9 forks source link

PA handling side-effects #322

Open cl4yton opened 1 year ago

cl4yton commented 1 year ago

We have done some limited handling of side-effecting on the GCC-side. E.g., there should be some handling (within the annCAST passes) of identification of globals being assigned, and capturing this in some the annCAST (needs review).

But we do not currently have a general approach to handling side-effects / wiring.

For example, for the use of side-effecting functions or the Python assignment-expression Walrus Operator:

z = -5
b = -10
a = -5

print(a)

def temp_a(b):
    global a
    a = max(2, b)
    return a

if ( z - 20 < a or not(z < temp_a(b)) ) and ...:
    print("if_body", z, a)
else:
    print("else_body", z, a)

With the Walrus Operator:

z = -5
b = -10
a = -5

print(a)

if z - 20 < a or not(z < (a := max(2, b))):
    print("if_body", z, a)
else:
    print("else_body", z, a)

These cases need to be handled.

It seems that the general solution requires passing side-effected updated variables as part of expression return values, so likely require use of packing/unpacking. (Gromet FN aim to be monadic, so need to massage side-effecting into monadic framework.)