cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

An error in Mathcad Prime and 15 programming

ValeryOchkov
24-Ruby IV

An error in Mathcad Prime and 15 programming

I think it is an error in Mathcad Prime 2.0 and 15 programming:

V1.png

4 REPLIES 4

I disagree, Valery. Implicit local variable creation has long been a feature of Mathcad and changing it would require a rework of most of my worksheets.

In the case of the function you have given in example, I usually use my own variant of match which deliberately does what you've demonstrated so that I can explicity handle the 'no match' situation - it's clearly identified by being a scalar (I have a few programs that return -1 to ensure that the result isn't treated as a valid index into a zero-based array).

It's simple enough to emulate the match behaviour if you want to:

collab - 12 06 08 undefined local variables 01.JPG

I'm more scared of the side-effects of introducing a change to this than I am of living with the occasional error ...

Stuart

StuartBruff wrote:

I disagree, Valery.

Sorry than You must be agree that 0>1

a.png

This is the programming language BASIC rudimetn.
If the variable is not defined, it defaults to zero.
Because of this peculiarity of this language was happening a lot of bugs
:

spap.png

I'll agree to anything if you pay me enough, Valery! 0>1? π=3? Heck, why be stingy, let's large it up and let π=4. No Problem.

Sigh. The problem with life and real maths is that there is often a set of contradictory solutions that mess up or prevent a given solution by choosing another. It's like the old base index 0 or 1 quandry. The advantage of enforcing variable definitions is that you make sure that everything has the correct value. The disadvantage is that quick and easy implementation gets a little more complex with the need to think of more things. Beginners, the careless and people having a "bad hair" day can suffer without safeguards. OTOH, as long-serving Mathcadders can testify to, putting those safeguards in place can visit all kinds of horrors on those who are having slightly better days.

Remember what Mathcad 12 introduced? SUC and protecting the little ones against hurting themselves with regression REALLY messed up a lot of my worksheets and prevented me from exploring some interesting recursive functions.

What I think would be a better solution is to introduce an 'empty' constant (Nothing, Null, Nil, whatever) and return that by default. Such a variable should return an error if (conventional) mathematical operations are carried out on it (eg 9+nil => error) but be allowed in some functions, such as stack, where they can act like "" does when concatenating strings ... hmm, on second thoughts it might be better to have an explicit Empty constant and an explicit Null?

Additionally, there could be a Worksheet Option to turn on "Explicit Local Variable Declaration" - that should provide an adequate "comb" for straightening things out.

Stuart

(For some reason I haven't been able to fathom, what Mathcad 12 did with recursion made me far more annoyed than SUC did. With SUC I only felt like machine-gunning a few thousand people, but the changes to recursion made me think in terms of nuclear weapons ... big ones. I think maybe it was because Mathcad 12 originally almost got it right in the first beta, but then lost the plot. Such a shame, because recursion is so useful once the brain's been wrapped around it a few times)

MikeArmstrong
5-Regular Member
(To:StuartBruff)

Great discussion fellers.

Mike

Top Tags