Skip to content

Constant substitution in CategoricalExprs #10

Description

@Legotier

Running the program

prog = compile_pgcl("""
    const c := 42
    nat x
    x := c : 1/2 + 2 : 1/2
    x := c
""")
print(prog)

gives the following output:

const c := 42;
nat x;
x := c : 1/2 + 2 : 1/2;
x := 42;

The constant in the categorical expression isn't substituted. This happens because the different subexpressions in a CategoricalExpr aren't stored as top-level attributes (sensible), but in a list of subexpressions with probabilities. This however means that the built-in walk over the expression doesn't yield these subexpressions due to the way children are discovered in mut_expr_children.

I already changed this on the brand-new branch to enable walking over the parameters of a function call. However, the problem with CategoricalExprs persists, as their subexpressions are stored in tuples, which are immutable and thus don't allow for substitution.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions