[metapost] short-circuit logic

Nicola nvitacolonna at gmail.com
Thu Jun 23 16:41:29 CEST 2011

In article <BANLkTikrBj5O7iw08AmGyquMzX0CQUH68w at mail.gmail.com>,
 Troy Henderson <thenders at gmail.com> wrote:

> Does MetaPost have a short-circuit logical "or" and "and"?

The METAFONTbook, Appendix D, defines:

def cand(text q) = startif true q else: false fi enddef; 
def cor(text q) = startif true true else: q fi enddef; 
tertiarydef p startif true = if p: enddef;

Now you can write things like:

if pair x cand (x>(0,0)): A else: B fi;
if unknown x cor (x<0): A else: B fi;

The right-hand operands /must/ be enclosed in parentheses. But I think this is a 
minor drawback (I always use parentheses anyway).


More information about the metapost mailing list