Message Boards Message Boards

0
|
7151 Views
|
6 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Make conditional statement work in M10.0.2?

Posted 9 years ago

Hello,

I am following a YouTube Wolfram Language Fundamentals lecture. I cannot make the condition example at the link's time stamp work in Mathematica Home 10.0.2. The date of the YouTube lecture is Oct 28, 2014 and Mathematica 10.0.2 came out on Dec 15, 2014. Why doesn't this statement work?

{a, b, c} /. { c \[RightArrow] b, b \[RightArrow] a}

I get this error message:

ReplaceAll::reps: {c\[RightArrow]b,b\[RightArrow]a} is neither a list of replacement rules
nor a valid dispatch table, and so cannot be used for replacing. >>

I tried adding spaces, clearing variable names, exiting and re-entering Mathematica, using a new notebook, etc..., but nothing worked. Can someone tell me why the above statement does not work?

Thanks.

POSTED BY: Dan M
6 Replies

It seems that you copied the code and the "->" (\[Rule]) was interpreted as the \[RightArrow]. So the following code must work:

In[5]:= {a, b, c} /. {c -> b, b -> a}

Out[5]= {a, a, b}
POSTED BY: Marco Thiel
POSTED BY: Marco Thiel
Posted 9 years ago

Thanks for the help. I rewrote the statement and it worked. In the "Basic Math Assistant", a right arrow is both in the Calculator area and the Typesetting>Arrows areas. I used dash and greater than, "->", to write the statement.

POSTED BY: Dan M

Unfortunately, this behavior of the site is somewhat frequent... I mean delayed appearing of the comments.

As a novice you should get a habit of looking in docs. There are many examples and you would understand the nature of error very quickly. Even syntax like /. can be looked up in docs:

enter image description here

POSTED BY: Sam Carrettie
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract