On 2/11/2010 9:05:26 PM, Tom Gutman wrote:
>You can't convert existing if
>statements to the new form,
>the semantics are
>incompatible. Currently, in a
>series of if statements, all
>the statements whose
>conditions evaluate to true
>are evaluated. In ane
>if/elseif/else construct only
>one statement, the first one
>whose condition is true, is
>evaluated.
That's a good point, but it's easily fixed by allowing an and_if statement as well as an else_if statement. A little unconventional (I am not aware of any other language that has this), but it is clear what it means.
>Also note that a series of
>expressions each followed by a
>condition (with a separator of
>if or when) is the standard
>way mathematicians write
>piecewise defined functions.
>Do you really wish to force a
>different notation, one taken
>from programming languages
>rather than mathematical
>usage?
I think you are only half right here. First, what we have now is also not standard math notation. For those that don't know what standard notation looks like, it can be seen here
http://en.wikipedia.org/wiki/Piecewiseand here
http://mathworld.wolfram.com/PiecewiseFunction.htmlIf you use that notation there is no "otherwise" allowed (someone can correct me if I am wrong about that, but I believe that is true). Further, the conditions must be exclusive (so it is never possible for two conditions to be met), and all conditions must be accounted for. If either of these things is not true then the definition is not valid.
Second, we are talking about programming constructs. It's not possible for a Mathcad program to adhere to standard math notation all the time anyway. So if I have to make a choice between the current notation, which is closer to standard math notation, but not standard and not clear, or a new notation that is less like standard math notation, but close to standard programming notation and very clear, I'll go with the latter.
Just to make the point, take
statement1 if condition1
statement2 if condition2
statement3 if condition3
statement4 otherwise
if you don't know Mathcad very well, what does this do? Does it execute all the statements for which the condition is true, or does it drop out of the block when it finds the first one? Is it even a block, or are the if statements all independent and the "otherwise" only applies to the last one? There is no way to know just by looking at it, and that is a problem. The proposed new notation is completely clear.
Apart from the programming structure though, I would like to have the standard math notation available. As an option though, not as the only way to write conditional statements, because the requirements that only one condition can be met and all cases must be accounted for are too restrictive.
Richard