Skip to content

The visits() function, when used in branch node, returns the visit count of the clause rather than the branch node. #7

@brwarner

Description

@brwarner

Given the following branch node:

Image

Expected Behaviour:

  • The first time the branch is hit, the if clause is selected
  • The second time, the elseif
  • The third time, the else
  • And then the else from then on

Observed behaviour:

  • First time, the if
  • Second the, the else (strange!!)
  • Third time, the elseif
  • Each subsequent time, the else

Why is this happening?

Based on what I can see of how the ID's are being used, when evaluating conditions in branches, the ID of the condition (meaning that specific clause) is being used rather than the ID of the owning branch node. That means it's actually counting the visits of each clause, not the branch node as a whole.

The observed behaviour now makes more sense.

Image

During our first run through, the visit count of the if condition is 0, so we go through.

The second run, the if condition has a visit count of 1, so it fails. However, the visit count of the elseif clause is still 0 because we're counting the visits to the clause, not the whole node. So the visit count of elseif is 0, not 1, and so that fails and we fall down into the else.

On the third visit, the visit count of the elseif is now 1 since we evaluated it last round, so the elseif finally passes.

Is this intentional?

It's possible this is by design but it seems highly unintuitive.

Suggested Fix

When evaluating conditions in a branch node, have the visits() function return the visit count of the branch node itself rather than the individual clause. This may mean some restructuring because I don't think you actually ever count visit counts of branches since they're never transpiled.

Maybe a new TranspileBranch which just returns which output returned true?

Happy to discuss more.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions