Becomes

From Lazarus wiki
Revision as of 10:23, 9 May 2016 by Wtwangcb (talk | contribs)
Jump to navigationJump to search
:=


The symbol  := (the symbol colon followed by the symbol equal without intervening space or other character) is pronounced becomes,and is used in Pascal to mean is assigned the value of:

 A := 4 ;
 Circle_Area := Pi * Diameter ;
 Name := 'Smith' ;
 C := 1000 - C div 2 ;

The purpose in using two characters for assignment (instead of just one, say, the = sign) is to distinguish between assignment of value and comparison for equality.

For example, in languages other than Pascal one can write

A = B = D ;
or
A = B = D

depending on whether semicolons are required by that language.

The meaning of this expression is different depending on the language. For example, in Fortran and Basic, the statement would mean to set variable A to the value of the question is B equal to D? In the C Programming Language, the statement would mean to set variables A and B to the value of D. This type of instruction being in error is common enough in the C Programming Language it is often flagged by the compiler with a warning unless you tell the compiler that you intend to do this (multiple assignment) by putting parenthesis around the expression. (The correct way to get a test for equality in the C Programming Language is to use A = B == D; ).

In Pascal, this confusion cannot happen because the statement is illegal. One would write

A := B = D;

Which would mean the same thing as Fortran or Basic, i.e. to assign to A the answer to the question of "are B and D equal?"

To assign A, B and D the same value would require explicit separate assignments of the form

A := D ; B := D ;
or
B := D ; A := B ;
or
A := D ; B := A ;

Depending on whether there is a difference in execution or side effects (D could be a dynamic variable like a system port, a function or a property of an object, thus the value of the identifier D might be different between the first and second use.)


navigation bar: topic: Pascal symbols
single characters

+ (plus)  •  - (minus)  •  * (asterisk)  •  / (slash)
= (equal)  •  > (greater than)  •  < (less than)
. (period)  •  : (colon)  •  ; (semi colon)
^ (hat)  •  @ (at)
$ (dollar sign)  •  & (ampersand)  •  # (hash)
' (single quote)

character pairs

<> (not equal)  •  <= (less than or equal)  •  := (becomes)  •  >= (greater than or equal)

 •  >< (symmetric difference)  •  // (double slash)