Difference between revisions of "Becomes"

From Lazarus wiki
Jump to navigationJump to search
(new)
 
(more detail)
Line 1: Line 1:
The word '''''becomes''''' is how one pronounces the two-character symbol ''''':=''''' ([[colon]] followed by [[equal]]).  := is used in Pascal to mean ''is assigned the value of''. The purpose is to distringuish between assignment of value and comparison for equality.
+
The symbol ''''' := ''''' (the symbol [[colon]] followed by the symbol [[equal]] without intervening space or other character).  := is used in Pascal to mean ''is assigned the value of'':
 +
 
 +
: A := 4 ;
 +
: Circle_Area := Pi * Diameter ;
 +
: Name := 'Smith' ;
 +
 
 +
The word '''''becomes''''' is how one pronounces the two-character symbol := 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
 
For example, in languages other than Pascal one can write
Line 5: Line 11:
 
:or
 
:or
 
:A = B = D
 
:A = B = D
depending on whether semicolons are required.
+
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;''''' ).
+
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
 
In Pascal, this confusion cannot happen because the statement is illegal.  One would write
Line 24: Line 30:
  
  
[[Category:Symbols]]
+
<P>[[Category:Symbols]]
 
{{Symbols}}
 
{{Symbols}}

Revision as of 18:55, 10 May 2006

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

A := 4 ;
Circle_Area := Pi * Diameter ;
Name := 'Smith' ;

The word becomes is how one pronounces the two-character symbol := 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 (D could be a function or an object with a default property, 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)