Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
All,
In Mathcad Prime a variable can be globally defined only once in a worksheet - you cannot redefine a variable, either with a normal definition or a global definition operator, if it has already been defined globally - the math region containing the redefinition will error. The reasoning behind this is that a global definition should mean that variable is defined globally (it has the assigned value everywhere in the document); syntactically it makes sense to enforce this restriction.
In MC15 a variable can be redefined, both with a normal definition and globally:
Is this something that you do in MC15? If so, in what scenario would you do this?
In Prime, one concern we have with restricting global definition to once per worksheet per variable is on conversion of MC15 or earlier documents that include such redefinitions. There are several ways we could deal with these.
(1) Use the Mathcad Prime 2.0 behavior of adding a spec table of definitions at the top of the worksheet.
(2) Replace redefined global definitions in the worksheet with normal definitions.
(3) Convert as is and error on the global definitions:
What are your thoughts on this?
Welcome, Andrew, to PlanetPTC!
Welcome also to Groups:
I only use global definitions for two things:
1) I have a collapsed area with extra units, etc, defined. I use global definitions in this area so that I can put the area either at the start or the end of the worksheet. In practice, I almost never put it at the end though.
2) If I have a graph, and I want to see what happens when I change a variable that's higher up the worksheet. Then I put a global definition next to the graph, and disable the normal definition.
So I would actually find it more useful if inserting a global definition (or converting a worksheet with global and a normal definitions) if the normal definitions were disabled in some way (as opposed to having them error, which will lead to undefined variable errors). If I delete the global definition then the local definitions should be reenabled. That means they would need to be disabled in a way that's different to the way we can disable an expression now.
I agree with Richard. (I don't like global definitions, almost never use them, most often in his example 2) above.)
Having a global definition disable any local definition makes sense, it would be good to have this flagged (with a different color squiggly underline?)
Sorry about joining late...I can't log in to the community the usual way, and only "discovered" by accident that I can log in via the problem report page. So I filed a report, and jumped over here 😉
I use global defs for unit declarations that are not in Mathcad but that I use routinely. I have a library worksheet that I include via my Mathcad template. It is mostly units and constants that I use, well, constantly 😉 and some common functions that I use often.
In a worksheet, I use a global to make clear my intent, and to be able to change a value that affects calculations earlier in the document. Working with other programming languages, I have gotten used to the idea that there are things that I can define as unchangeable, and I like that.
I think that having global and local vars with the same name should be an error.
I have mixed thoughts about whether I can change a global or not. I lean toward being allowed to have only one declaration of a global variable. If I can assign it different values at different point in the doc, what's the point? But if I am 3 pages down and want to see the effect of changing a global, and this /is/ something that I use, I want to be able to declare the global var at that point. I use the symbolic ctrl= to document my intent early on, and note in the doc that it is actually set farther along. It's extra work for me, but it helps me keep track of what I am doing.
Of your options listed above, these were my only considerations
(2) Replace redefined global definitions in the worksheet with normal definitions.
(3) Convert as is and error on the global definitions:
and, per my reasoning above, I think (3) is the best. I tend to be more formal in my development, and I think that being able to redefine a global, or worse, redefine is as a local, is not acceptable.
~R~