Re: Defining a predicate
- To: mathgroup at yoda.physics.unc.edu
- Subject: Re: Defining a predicate
- From: Roman Maeder <maeder at inf.ethz.ch>
- Date: Mon, 27 Jun 1994 10:38:18 +0200
> The following works: > > TableauQ[_] := False > TableauQ[{_Equal..}] := True > > However, the logic of providing a blanket False (TableauQ[_] := > False), which is then overridden when appropriate pattern matches, > bothers me. Is the explicit False necessary? > > On p. 227 of the good book, Wolfram writes: > > An important feature of Mathematica property-testing functions whose > names end in Q is that they always return False if they cannot > determine whether the expression has the given property. > > That behaviour also seems appropriate in my example. Is it possible > to make user defined predicates exhibit the same behaviour? Using names that end in Q is a convention; the desired behaviour is not automatic. Your use of the catchall rule is good programming style. You should, however, put that rule last. If there were any other rules with side condition (in the form TableauQ[..] /; cond := ...), the automatic rule ordering would not work. Roman Maeder