Date: Mar 21, 2013 12:55 AM
Author: Sseziwa Mukasa
Subject: Re: rookie code issue


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]


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

Regards,
Sseziwa