Category:ALGOL 68: Difference between revisions
Content added Content deleted
m (→Coercion (casting): clarify the difference between soft, week, meek, firm and strong typing.) |
|||
Line 144: | Line 144: | ||
coercions are available at a particular point in the program. These contexts are: |
coercions are available at a particular point in the program. These contexts are: |
||
{|class="wikitable" |
{|class="wikitable" |
||
!rowspan=2| N<br> |
|||
! Context name !! Context location !! Coercions available in this context!! Coercion examples |
|||
a<br> |
|||
m<br> |
|||
e |
|||
!rowspan=2| Context location |
|||
!colspan=5| Coercions available in this context |
|||
!rowspan=2| Coercion examples |
|||
|- |
|- |
||
|bgcolor=eeeeee|Soft |
|||
!soft |
|||
|bgcolor=dddddd|Meek |
|||
|| The LHS of assignments, as "~" in: <lang algol68>~ := ...</lang> |
|||
|bgcolor=cccccc|Weak |
|||
|| deproceduring |
|||
|bgcolor=bbbbbb|Firm |
|||
|| |
|||
|bgcolor=aaaaaa|Strong |
|||
* deproceduring of: <lang algol68>PROC REAL random: e.g. random</lang> |
|||
|- |
|||
!weak |
|||
|| |
|||
* Primaries of slices, as in "~" in: <lang algol68>~[1:99]</lang> |
|||
* Secondaries of selections, as "~" in: <lang algol68>value OF ~</lang> |
|||
|| all '''soft''' then weak dereferencing |
|||
|| |
|||
<lang algol68>REF BOOL to REF BOOL |
|||
REF REF INT to REF INT |
|||
REF REF REF REAL to REF REAL |
|||
REF REF REF REF STRUCT to REF STRUCT</lang> |
|||
|- |
|||
!meek |
|||
|| |
|||
* Trimscripts (yielding INT) |
|||
* Enquiries: e.g. as "~" in the following<lang algol68>IF ~ THEN ... FI</lang> and <lang algol68>FROM ~ BY ~ TO ~ WHILE ~ DO ... OD etc</lang> |
|||
* Primaries of calls (e.g. sin in sin(x)) |
|||
|| all '''weak''' then dereferencing |
|||
|| |
|||
<lang algol68>REF REF BOOL to BOOL |
|||
REF REF REF INT to INT</lang> |
|||
|- |
|||
!firm |
|||
|| |
|||
*Operands of formulas as "~" in:<lang algol68>OP: ~ * ~</lang> |
|||
*Parameters of transput calls |
|||
|| all '''meek''' then uniting |
|||
|| e.g. <lang algol68>UNION(INT,REAL) var := 1</lang> |
|||
|- |
|- |
||
!S<br> |
|||
!strong |
|||
t<br> |
|||
r<br> |
|||
o<br> |
|||
n<br> |
|||
g |
|||
||Right hand side of: |
||Right hand side of: |
||
* Identity-declarations, as "~" in: <lang algol68>REAL x = ~</lang> |
* Identity-declarations, as "~" in: <lang algol68>REAL x = ~</lang> |
||
Line 191: | Line 174: | ||
* All parts (but one) of a balanced clause |
* All parts (but one) of a balanced clause |
||
* One side of an identity relation, as "~" in: <lang algol68> ~ IS ~</lang> |
* One side of an identity relation, as "~" in: <lang algol68> ~ IS ~</lang> |
||
|bgcolor=EEEEEE rowspan=4 width="50px"| deproc- eduring |
|||
|| all '''firm''' then widening, rowing and voiding |
|||
|bgcolor=DDDDDD rowspan=3 width="50px"| all '''soft''' then weak deref- erencing |
|||
||Widening occures if there is no loss of precision. For example: An INT will be coerced to a REAL, and a REAL will be coerced to a LONG REAL. But not vice-versa. Examples: |
|||
|bgcolor=CCCCCC rowspan=2 width="50px"| all '''weak''' then deref- erencing |
|||
|bgcolor=BBBBBB rowspan=1 width="50px"| all '''meek''' then uniting |
|||
|bgcolor=AAAAAA width="50px"| all '''firm''' then widening, rowing and voiding |
|||
|colspan=1 bgcolor=AAAAAA| |
|||
Widening occurs if there is no loss of precision. For example: An INT will be coerced to a REAL, and a REAL will be coerced to a LONG REAL. But not vice-versa. Examples: |
|||
<lang algol68>INT to LONG INT |
<lang algol68>INT to LONG INT |
||
INT to REAL |
INT to REAL |
||
Line 198: | Line 186: | ||
BITS to []BOOL |
BITS to []BOOL |
||
BYTES to STRING</lang> |
BYTES to STRING</lang> |
||
A variable can also be coerced (rowed) to an array of length 1. |
A variable can also be coerced (rowed) to an array of length 1. |
||
For example: |
|||
<lang algol68>INT to [1]INT |
<lang algol68>INT to [1]INT |
||
REAL to [1]REAL</lang> etc |
REAL to [1]REAL</lang> etc |
||
|- |
|||
!F<br> |
|||
i<br> |
|||
r<br> |
|||
m |
|||
|| |
|||
*Operands of formulas as "~" in:<lang algol68>OP: ~ * ~</lang> |
|||
*Parameters of transput calls |
|||
|colspan=3 bgcolor=BBBBBB| Example: |
|||
<lang algol68>UNION(INT,REAL) var := 1</lang> |
|||
|- |
|||
!M<br> |
|||
e<br> |
|||
e<br> |
|||
k |
|||
|| |
|||
* Trimscripts (yielding INT) |
|||
* Enquiries: e.g. as "~" in the following |
|||
<lang algol68>IF ~ THEN ... FI</lang> and |
|||
<lang algol68>FROM ~ BY ~ TO ~ WHILE ~ DO ... OD etc</lang> |
|||
* Primaries of calls (e.g. sin in sin(x)) |
|||
|colspan=4 bgcolor=CCCCCC|Examples: |
|||
<lang algol68>REF REF BOOL to BOOL |
|||
REF REF REF INT to INT</lang> |
|||
|- |
|||
!W<br> |
|||
e<br> |
|||
a<br> |
|||
k |
|||
|| |
|||
* Primaries of slices, as in "~" in: <lang algol68>~[1:99]</lang> |
|||
* Secondaries of selections, as "~" in: <lang algol68>value OF ~</lang> |
|||
|colspan=5 bgcolor=DDDDDD|Examples: |
|||
<lang algol68>REF BOOL to REF BOOL |
|||
REF REF INT to REF INT |
|||
REF REF REF REAL to REF REAL |
|||
REF REF REF REF STRUCT to REF STRUCT</lang> |
|||
|- |
|||
!S<br> |
|||
o<br> |
|||
f<br> |
|||
t |
|||
|| The LHS of assignments, as "~" in: <lang algol68>~ := ...</lang> |
|||
|colspan=6 bgcolor=EEEEEE| Example: |
|||
* deproceduring of: <lang algol68>PROC REAL random: e.g. random</lang> |
|||
|} |
|} |
||
For more details about Primaries and Secondaries refer to [[Operator_precedence#ALGOL_68|Operator precedence]]. |
For more details about Primaries and Secondaries refer to [[Operator_precedence#ALGOL_68|Operator precedence]]. |