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 ]
Bob Hanlon

Posts: 892
Registered: 10/29/11
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

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@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
>





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.