MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

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: &gt; Hi, &gt; &gt; hmm, and 
TrueQ[] does what ? &gt; &gt; TrueQ[expr] yields True if expr is True, 
and yields False otherwise. &gt; &gt; why do you want to to know if 
expr is False if you can check &gt; that it is true ? &gt; &gt; Regards 
&gt; jens &gt; &gt; Murray Eisenberg wrote: &gt; &gt;&gt;When type 
checking the argument to a function, it's often easy to use a 
&gt;&gt;built-in object in a pattern, e.g.: &gt;&gt; &gt;&gt; 
f[n_Integer] := n + 1 &gt;&gt; &gt;&gt; g[x_?Positive] := Sqrt[x] 
&gt;&gt; &gt;&gt;But what about type-checking that an argument is 
Boolean, i.e., True or &gt;&gt;False? Of course it's easy enough to 
define a function to do this: &gt;&gt; &gt;&gt; tfQ[sym_] := 
MemberQ[{True, False}, sym] &gt;&gt; (* or: tfQ[sym_] := Element[sym, 
Booleans] *) &gt;&gt; &gt;&gt; h[y_, flag_?tfQ] := .... &gt;&gt; 
&gt;&gt;But is there no NAMED, single built-in object that does what 
the &gt;&gt;above-defined tfQ does? &gt;&gt; &gt;&gt;If I am correct 
that there is not, this may result from what seems to be &gt;&gt;a 
fundamental language design decision, namely, that True and False are 
&gt;&gt;just symbols -- they do have head Symbol -- rather than being 
of a &gt;&gt;special type having, say head Boolean. Why was that design 
decision made? &gt;&gt; &gt;&gt;-- &gt;&gt;Reply to &quot;REPLY 
TO&quot; address and NOT to the &quot;FROM&quot; address!! 
&gt;&gt;Otherwise I will never see your reply!!!!!!!!!!!!!!!!!!!!!! 
&gt;&gt; &gt;&gt;Murray Eisenberg murray at math.umass.edu 
&gt;&gt;Mathematics &amp; Statistics Dept. &gt;&gt;Lederle Graduate 
Research Tower phone 413 549-1020 (H) &gt;&gt;University of 
Massachusetts 413 545-2859 (W) &gt;&gt;710 North Pleasant Street fax 
413 545-1801 &gt;&gt;Amherst, MA 01003-9305 &gt; &gt; &gt; -- Reply to 
&quot;REPLY TO&quot; address and NOT to the &quot;FROM&quot; address!! 
Otherwise I will never see your reply!!!!!!!!!!!!!!!!!!!!!! Murray 
Eisenberg murray at math.umass.edu Mathematics &amp; 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 


  • Prev by Date: Re: RE: Quick "Random[]" question
  • Next by Date: Re: Re: Re: A bug?......In[1]:= Sum[Cos[x], {x, 0, Infinity, Pi}]......Out[1]= 1/2
  • Previous by thread: Re: Re: Boolean type-checking
  • Next by thread: Re: Re: Boolean type-checking