Make conditional statement work in M10.0.2?

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.

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}

Hi Dan,

your problem is that you used RightArrow, whereas you should use Rule. This is a bit difficult to see in the output:

So it looks the same but it is not. The following lines show what is going on:

{a, b, c} /. {c \[RightArrow] b, b \[RightArrow] a} // Hold // FullForm
{a, b, c} /. {c -> b, b -> a} // Hold // FullForm

The sceenshot shows the output.

So the issue is that both RightArrow and Rule are rendered in the same way. If you type it in as → it should work.

Cheers,

Marco

Sorry. My reply is much later but your did not show up until after I posted. Sorry.

Cheers,

Marco

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.

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: