Post Reply 
Somewhere between a bug or feature:
11-14-2014, 05:18 PM
Post: #8
RE: Somewhere between a bug or feature:
Here's how I understand the where function (now).

1. Any expression in front of the | symbol is considered to be part of the expression that will be used for substitution, unless the user specifically adds in ()'s to limit the scope of the | operator. For example:

a+b^2|b=4 is treated as (a+b^2)|b=4

which makes sense to me as we would otherwise be forced to add in ()'s every time we use the | operator.

2. If the expression it a single variable that is defined, then the variable will be recalled, and this result is what becomes the expression for substitution. Otherwise, the expression is left as is.

restart;
b:=x^2;
b|x=2; --> 4

On the other hand,

a+b|x=2; --> a+x^2

There is nothing to substitute into a+b because rule #2 doesn't apply and there is no x in "a+b". Then a+b is evaluated to a+x^2 because b=x^2. We get the same result as if we only typed in a+b.

3. In the case of storing values via the := symbols, it is generally the case that the right hand side is evaluated first prior to storing. However, in conjunction with |, it appears that rule #1 above has higher priority. So typing a:=b|x=2 gets parsed as (a:=b)|x=2 (per rule #1). However, there is no x in the expression a:=b, so nothing is substituted. Finally, a:=b is passed for evaluation, which results in x^2 being stored into a. That is, (a:=b)|x=2 is no different from just typing a:=b as there is no x in "a:=b"

I am not sure I agree with this. I am of the opinion that the | operator should check for a valid "beginning" and not assume that the start of the entry line is the beginning. That is, the := should have higher priority than the | operation. That said, this comes down to a personal preference. When we start mixing actual mathematical operators (e.g. the | operator) with non-mathematical operators (e.g. :=), the question of which should have higher priority will never be truly sorted out to everyone's satisfaction. All we can expect is that the rules are consistent. In this case, it appears that they are.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Somewhere between a bug or feature: - DrD - 11-13-2014, 05:52 PM
RE: Somewhere between a bug or feature: - Han - 11-14-2014 05:18 PM



User(s) browsing this thread: 4 Guest(s)