MathGroup Archive 2013

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

Search the Archive

Re: rookie code issue

  • To: mathgroup at smc.vnet.net
  • Subject: [mg130216] Re: rookie code issue
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Thu, 21 Mar 2013 00:56:50 -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
  • References: <20130320082258.D93A969F1@smc.vnet.net>

While they are not equal they are the same, i.e., test with SameQ
(===) rather than Equal

The issue presumably arises because Which has the attribute HoldAll
and this seems to cause the intended Equal test to be viewed as an
equation.

Attributes[Which]

{HoldAll, Protected}


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

2


Bob Hanlon


On Wed, Mar 20, 2013 at 4:22 AM,  <robholman at gmail.com> wrote:
> Hi folks:
>
> I'm working on a bit of code in which I want students to choose a trig function from a drop-down menu, and then from there have some choices for viewing the graph. All is working fine except for one thing. There are a couple of constants that depend on the function they choose from the menu, and I'm trying to define the constant based on their choice for f. The basic issue I'm having boils down to the following question:
>
> Why doesn't the following code return a 2?
>
>
> m = Cos;
> Which[m == Sin, 5, m == Cos, 2]
>
>
>
> Thanks for the help!
>
> Rob
>



  • Prev by Date: Re: rookie code issue
  • Next by Date: Re: rookie code issue
  • Previous by thread: Re: rookie code issue
  • Next by thread: Re: rookie code issue