missing values and logical operators

CODAP Forums CODAP Help Forum missing values and logical operators

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #6500 Score: 0
    Thomas Castleman
    Participant
    3 pts

    Hi,

    I noticed the following behavior with regard to missing values:

    The formula false and missing short circuits and evaluates to false. This seems expected since even though the value of the righthand side is unknown, the false is enough to determine the overall expression must be false.

    However, with missing and false, the and operator seems to propagate the missing value, instead of determining that the result must be false. Is this intended?

    Is this because missing values are considered falsy, and and short circuits and evaluates to the lefthand side if it is falsy?

    Thanks,

    Thomas

    #6501
    Jonathan Sandoe
    Keymaster

    Hello Thomas,

    What an interesting question! The short answer is that expressions are evaluated as Javascript expressions and this is the behavior in Javascript. Here is a snippet I copied from a node session that confirms this:

    > var missing = “”;
    undefined
    > [missing && false, false && missing, true || missing, missing || true];
    [ ”, false, true, true ]

    This is consistent with your explanation, just putting it another way.

    You have probably also discovered that there are other places where the commutative property of ‘and’ and ‘or’ is not observed:

    Although this behavior is consistent with expressions in the Javascript language, it is not consistent with boolean logic and likely to be confusing to students. I will file a bug. The delegation of CODAP’s expression language to Javascript is pretty fundamental to CODAP’s formula engine, so it may take a while to explore the implications elsewhere in CODAP.

    Jonathan

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.