Philip Newton (pne) wrote,
Philip Newton

  • Mood:

How Lojban can help you with programming

I had a test in a program I'm writing which tested three truth values; let's call them A, B, and C. At the moment, it's testing for A && B && C (that is, they all have to be true at once).

After debugging, I realise that that's not what I want; I actually want the test to be "if A, then if B then also C" [but if A and not-B, then I don't care about C], but I wasn't sure how to express an "if" relationship with logical operators.

Enter Lojban :) I remembered that "logical if" as in "if X, then Y" is "ganai X gi Y". Translated back into logics, that's "not-X or Y". (For the curious who are not familiar with Lojban, the "a" bit of "ganai" is responsible for the "or" meaning, and the "nai" bit for the "not" meaning. The "g" of "ganai", as well as the word "gi", are used for all forethought logical connectives.)

After a quick sanity check I realised that this is what I wanted—if A is true, and either B is not true or [B is true and] C is true, then the bit of code should be executed. Changed "if (A && B && C)" to "if (A && (!B || C))" and away I went!

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded