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

What are the differences between := in regular math block and <- in loop block?

SOLVED
Highlighted
Marble

What are the differences between := in regular math block and <- in loop block?

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: What are the differences between := in regular math block and <- in loop block?

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

 

View solution in original post

7 REPLIES 7
Highlighted

Re: What are the differences between := in regular math block and <- in loop block?

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

 

View solution in original post

Highlighted

Re: What are the differences between := in regular math block and <- in loop block?

LucMeekes_0-1589810120180.png

Success!

Luc

Re: What are the differences between := in regular math block and <- in loop block?

Could you please explain what does each means? 

Highlighted

Re: What are the differences between := in regular math block and <- in loop block?

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 <-.

LucMeekes_0-1589812092625.png

Success!
Luc

 

Highlighted

Re: What are the differences between := in regular math block and <- in loop block?


@LucMeekes wrote:

LucMeekes_0-1589810120180.png


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

Highlighted

Re: What are the differences between := in regular math block and <- in loop block?

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!

Highlighted

Re: What are the differences between := in regular math block and <- in loop block?

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.

Announcements