Difference between revisions of "Becomes"

From Lazarus wiki
Jump to navigationJump to search
m (Reverted edits by Parrishcartwright (Talk); changed back to last version by Djzepi)
m (Text replace - "delphi>" to "syntaxhighlight>")
Line 5: Line 5:
 
The symbol ''''' := ''''' (the symbol [[Colon|colon]] followed by the symbol [[Equal|equal]] without intervening space or other character) is pronounced '''''becomes''''',and is used in [[Pascal]] to mean ''is assigned the value of'':
 
The symbol ''''' := ''''' (the symbol [[Colon|colon]] followed by the symbol [[Equal|equal]] without intervening space or other character) is pronounced '''''becomes''''',and is used in [[Pascal]] to mean ''is assigned the value of'':
  
<delphi>
+
<syntaxhighlight>
 
  A := 4 ;
 
  A := 4 ;
 
  Circle_Area := Pi * Diameter ;
 
  Circle_Area := Pi * Diameter ;
 
  Name := 'Smith' ;
 
  Name := 'Smith' ;
 
  C := 1000 - C div 2 ;
 
  C := 1000 - C div 2 ;
</delphi>
+
</syntaxhighlight>
  
 
The purpose in using two characters for assignment (instead of just one, say, the = sign) is to distringuish between assignment of value and comparison for equality.
 
The purpose in using two characters for assignment (instead of just one, say, the = sign) is to distringuish between assignment of value and comparison for equality.
Line 23: Line 23:
  
 
In Pascal, this confusion cannot happen because the statement is illegal.  One would write
 
In Pascal, this confusion cannot happen because the statement is illegal.  One would write
<delphi>
+
<syntaxhighlight>
 
A := B = D;
 
A := B = D;
</delphi>
+
</syntaxhighlight>
 
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?"   
 
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?"   
  

Revision as of 14:56, 24 March 2012

:=


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 distringuish 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)