The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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 ]
Sseziwa Mukasa

Posts: 108
Registered: 8/26/07
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

On Mar 20, 2013, at 4:22 AM, wrote:

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

Because == doesn't return a boolean value comparing Symbols:

(Debug) In[7]:= Cos == Sin
(Debug) Out[7]= Cos == Sin

Equal is intended for use with numeric quantities, use Same (===) instead:

(Debug) In[6]:= Which[m === Sin, 5, m === Cos, 2]
(Debug) Out[6]= 2


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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.