Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
From my (very limited) experience, in the (if, while) loop, Mathcad doesn't allow := but only <-. I was just wondering how are they differ from one another.
Thank you!
Solved! Go to Solution.
They are both assignment operators, but the left arrow is used within a programming structure, while the := is only used outside a programming structure.
Why this is the case, I've no idea!
Alan
They are both assignment operators, but the left arrow is used within a programming structure, while the := is only used outside a programming structure.
Why this is the case, I've no idea!
Alan
Success!
Luc
Could you please explain what does each means?
The first example shows assignment to a worksheet variable named SomeVariable. It gets the result of a program. The program simply assigns 5*3+1 (=16) to a local variable named OtherVariable.
The second example is impossible. Try it out, you cannot type it in the way it shows. I've constructed it to be able to show.
I guess Mathcad needs a simple way to distinguish between local assignments (within a program) and assignments to worksheet variables and functions. Hence the := and the <-.
Success!
Luc
@LucMeekes wrote:
Is that slightly "cart before the horse", Luc? Is it only not possible because the implementation won't let you do it?
If you consider := as a global-ish definition operator, what philosophical design issue is there with chaining multiple := definition operators? On the face of it, a:=b:=c:=5*3+1 seems reasonable. (ISTR being able to chain local definitions)
In your example, OtherVariable is a local variable that has no existence outside of the assignment, whereas is my example, b and c would be defined from that point onwards.
I suspect one of the answers to Alan's question (why they are different) is that it helps mitigate external side effects taking place within a program (as proper encapsulation should do). It should be possible to limit the scope of a definition operator, but it's probably easier to use a separate operator that behaves in a slightly different way (locally defined variables tend to behave more like 'normal' programming variables than constants).
Cheers,
Stuart
The global assignment operator (three bar equal sign) defines a variable EVERYWHERE on the sheet; the normal assignment { := } defines it below and to the right of the assignment. (This has always been true; you will recall.) The global assignment is useful if you want to temporarily vary a parameter you defined on page 1 and see the effects on page (much further.) You disable the original assignment, type the global assignment on page (much further) and you can see the effects of changes without needing to scroll the length of the sheet. ANY OTHER TIME the global assignment can be very dangerous!
As Alan says they're both assignment operators. The "left arrow." { <--} only works in program blocks. Assignments inside program blocks stay inside program blocks--the assignment isn't valid outside the program. The { :=} assignment is the more common one, out in "free Mathcad." That assigns the variable/function for the rest of the sheet (below and right of) unless it is overwritten by another assignment statement.