5
1> X = 10.
10
2> Y = 9.
9
3> X - 1 = Y.
* 1: illegal pattern
4> Y = X - 1.
9
5> 10 - 1 = Y.
9

Can you explain to me what illegal pattern in query 3> is? Thanks!

2240
  • 1,547
  • 2
  • 12
  • 30
moon2sun00
  • 51
  • 6

1 Answers1

7

The variable that you are binding to needs to be on the left side, not the right.

This is the correct expression:

Y = X - 1.
nu-ex
  • 691
  • 4
  • 9
  • 1
    Expression 5 is correct because it is a pattern match. With that line, you're saying "I want Y (which is 9) to be matched against 10 - 1 (which is 9)". Binding variables is just a special case of pattern matching, in expression 2 , you're saying "I want 9 to be matched against Y (which is unbound)." Since it is unbound, it can match anything and it is then bound to the variable from that point on. – Adam Lindberg Sep 07 '15 at 08:30
  • How about "I want Y (which is 9) to be matched against X - 1 (which is 9) in exp 3? – moon2sun00 Sep 08 '15 at 07:35
  • In 5 the shell is helping you a bit as it can see that the "pattern" can be evaluated so it does it and then checks that the result is a pattern. Which it is ``10``. In 3 this is not possible as there is no way that ``X-1`` can be interpreted as a patten, it is an expression. You can say that a pattern is something which describes what the structure of the data looks like and ``X-1`` does not do that. The handling of the shell in 5 is a bit confusing and probably shouldn't be done. – rvirding Sep 15 '15 at 13:49