MathGroup Archive 2013

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

Search the Archive

Re: rookie code issue

  • To: mathgroup at smc.vnet.net
  • Subject: [mg130212] Re: rookie code issue
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Thu, 21 Mar 2013 00:55:29 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net

On 3/20/13 at 4:22 AM, robholman at gmail.com wrote:

>Why doesn't the following code return a 2?

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

Notice

In[3]:= Head /@ {Cos, Sin}

Out[3]= {Symbol,Symbol}

So, by using Equal, you are asking Mathematica to determine
whether two symbols without assigned values are equal which it
cannot do.

What you want to use here is SameQ rather than Equal. That is

In[4]:= m = Cos;
Which[m === Sin, 5, m === Cos, 2]

Out[5]= 2




  • Prev by Date: Re: Smoothhistogram and log-log scaling; Fitting of a
  • Next by Date: Re: rookie code issue
  • Previous by thread: Re: rookie code issue
  • Next by thread: Re: rookie code issue