PreviousUpNext

5.7.12  Mythryl Conditionals

The Mythryl case statement is essentially identical to that of SML except for the addition of the long longed-for esac terminator:

    case (foo)
    1 => printf "I\n";
    2 => printf "II\n";
    3 => printf "III\n";
    _ => printf "Many!\n";
    esac;

The Mythryl if statement differs more from that of SML. The then and else clauses comprise implicit code blocks, which in many cases considerably reduces code verbosity. Also, the Mythryl version supplies a terminal fi in honor of the late Dijkstra:

    if  good                           # Conditional parens not needed around lone identifier.
        printf "Very good.\n";
        printf "Yes, very good indeed!\n";
    else
        printf "Not good.\n";
        printf "Doubleplus ungood!\n";
    fi;

Also, unlike SML, Mythryl allows the else clause to be dropped, in which case its value defaults to Void:

    if  good
        printf "Very good.\n";
        printf "Yes, very good indeed!\n";
    fi;

In additional to vanilla if, Mythryl also supports a C-flavored trinary conditional expression ... ?? ... :: ...:

    sprintf "%d cow%s" cows (cows > 1 ?? "s" :: "");

Finally, the and and or boolean operators are implemented using short-circuit evaluation, making them implicit conditionals:

    if (f != 0.0
        and
        (1.0 / f) > 2.0      # Cannot throw divide-by-zero exception.
       )
       printf "I feel silly!\n";
    fi;

Comments and suggestions to: bugs@mythryl.org

PreviousUpNext