MathGroup Archive 1997

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

Search the Archive

RE: Which, If and "neither True nor False"

  • To: mathgroup at smc.vnet.net
  • Subject: [mg9666] RE: [mg9652] Which, If and "neither True nor False"
  • From: jmthomas <jmthomas at cybercable.tm.fr>
  • Date: Fri, 21 Nov 1997 01:31:03 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

Try this:
Which[
a<b,DoSomething[],
a>c,DoSomethingElse[],
_,DoThis[]
]

Evaluation of Which returns the first value matching the test. The blank
matches any test and will return DoThis[] in the "unknown" case.

----------------------------------------------- Jean-Marie THOMAS
Conseil et Audit en Ingenierie de Calcul jmthomas at cybercable.tm.fr
+33 (0)3 88 32 93 64
www.cybercable.tm.fr/~jmthomas
=======================

-----Original Message-----
From:	Paul E Howland [SMTP:PEHOWLAND at dra.hmg.gb] To:
mathgroup at smc.vnet.net
Sent:	Tuesday, November 18, 1997 1:50 AM To:	mathgroup at smc.vnet.net
Subject:	[mg9652] Which, If and "neither True nor False"

I've just stumbled across a bug in some old code of mine, in which I had
a statement of the form:

Which[
        a<b, DoSomething[],
        a>c, DoSomethingElse[],
        True, DoThis[]
        ]

which I assumed would call DoThis[] if neither a<b nor a>c were True.
However, what I didn't realise is that if a is undefined, then the
first two conditions are neither True nor False, and Mathematica
returns the whole Which statement unevaluated!

The If statement has an optional fourth argument which is executed if
the test returns neither True nor False.  Is it possible to do the same
in a Which statement?  If not, why not?!

Paul

Paul E Howland PhD MEng CEng MIEE        Room BY209 Senior Scientist    
DERA (Malvern) Land Systems Sector                      St Andrews Road
Defence Evaluation & Research Agency     Malvern tel.
+44-(0)1684-895767                  Worcestershire fax.
+44-(0)1684-896315                  UK Email PEHowland at dera.gov.uk Web
Site http://www.dera.gov.uk
Official Disclaimer:
The views expressed above are entirely those of the writer and do not
represent the views, policy or understanding of any other person or
official body.




  • Prev by Date: RE: Which, If and "neither True nor False"
  • Next by Date: Re: Which, If and "neither True nor False"
  • Previous by thread: RE: Which, If and "neither True nor False"
  • Next by thread: Re: Which, If and "neither True nor False"