Re: Re: Re: Boolean type-checking
- To: mathgroup at smc.vnet.net
- Subject: [mg41876] Re: [mg41863] Re: [mg41811] Re: Boolean type-checking
- From: Bobby Treat <drmajorbob-MathGroup3528 at mailblocks.com>
- Date: Sat, 7 Jun 2003 11:45:00 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
f[True] := behavior1 f[False] := behavior2 f[True] f[False] f[other] behavior1 behavior2 f[other] Bobby -----Original Message----- From: Murray Eisenberg <murray at math.umass.edu> To: mathgroup at smc.vnet.net Subject: [mg41876] [mg41863] Re: [mg41811] Re: Boolean type-checking I want one behavior when the variable takes value True; another when that variable takes value False; and an unevaluated expression returned when the variable takes any other value (as by improper usage of the function). I do NOT want one behavior when the variable takes value True and an alternative in every other case! And I still raise the question as to why Mathematica does not have a built-in object for {True, False}. Jens-Peer Kuska wrote: > Hi, > > hmm, and TrueQ[] does what ? > > TrueQ[expr] yields True if expr is True, and yields False otherwise. > > why do you want to to know if expr is False if you can check > that it is true ? > > Regards > jens > > Murray Eisenberg wrote: > >>When type checking the argument to a function, it's often easy to use a >>built-in object in a pattern, e.g.: >> >> f[n_Integer] := n + 1 >> >> g[x_?Positive] := Sqrt[x] >> >>But what about type-checking that an argument is Boolean, i.e., True or >>False? Of course it's easy enough to define a function to do this: >> >> tfQ[sym_] := MemberQ[{True, False}, sym] >> (* or: tfQ[sym_] := Element[sym, Booleans] *) >> >> h[y_, flag_?tfQ] := .... >> >>But is there no NAMED, single built-in object that does what the >>above-defined tfQ does? >> >>If I am correct that there is not, this may result from what seems to be >>a fundamental language design decision, namely, that True and False are >>just symbols -- they do have head Symbol -- rather than being of a >>special type having, say head Boolean. Why was that design decision made? >> >>-- >>Reply to "REPLY TO" address and NOT to the "FROM" address!! >>Otherwise I will never see your reply!!!!!!!!!!!!!!!!!!!!!! >> >>Murray Eisenberg murray at math.umass.edu >>Mathematics & Statistics Dept. >>Lederle Graduate Research Tower phone 413 549-1020 (H) >>University of Massachusetts 413 545-2859 (W) >>710 North Pleasant Street fax 413 545-1801 >>Amherst, MA 01003-9305 > > > -- Reply to "REPLY TO" address and NOT to the "FROM" address!! Otherwise I will never see your reply!!!!!!!!!!!!!!!!!!!!!! Murray Eisenberg murray at math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305