Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: rookie code issue
Replies: 4   Last Post: Mar 21, 2013 12:55 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Murray Eisenberg

Posts: 2,097
Registered: 12/6/04
Re: rookie code issue
Posted: Mar 21, 2013 12:55 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

According to the reference page for Which:

If any of the Subscript[test, i] evaluated by Which give neither True nor False, then a Which object
containing these remaining elements is returned unevaluated.

So look at the following result:

Cos == Sin

You'll get back as output:

Cos == Sin

which is neither True nor False. On the other hand,

Cos === Sin (* using SameQ now *)

gives result False. Hence

m = Cos;
Which[m === Sin, 5, m === Cos, 2]

does give the result 2 that you wanted.

On Mar 20, 2013, at 4:22 AM, robholman@gmail.com wrote:

> ...Why doesn't the following code return a 2?
>
>
> m = Cos;
> Which[m == Sin, 5, m == Cos, 2]


---
Murray Eisenberg murray@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2838 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305









Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.