Anonymous user
Category:ALGOL 68: Difference between revisions
m
→Coercion (casting): clarify the difference between soft, week, meek, firm and strong typing.
(→Coercion (casting): more details) |
m (→Coercion (casting): clarify the difference between soft, week, meek, firm and strong typing.) |
||
Line 144:
coercions are available at a particular point in the program. These contexts are:
{|class="wikitable"
! Context name !! Context location !! Coercions
|-
!soft
|soft || deproceduring ▼
|| The LHS of assignments, as "~" in: <lang algol68>~ := ...</lang>
||
* deproceduring of: <lang algol68>PROC REAL random: e.g. random</lang>
|-
!weak
|weak || all ''soft'' above then weak dereferencing▼
||
* Primaries of slices, as in "~" in: <lang algol68>~[1:99]</lang>
* Secondaries of selections, as "~" in: <lang algol68>value OF ~</lang>
||
<lang algol68>REF
REF REF INT to REF INT
REF REF REF REAL to REF REAL
REF REF REF REF STRUCT to REF STRUCT</lang>
|-
|| all ''weak'' above then dereferencing▼
||
* 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))
||
<lang algol68>REF REF
REF REF REF INT to INT</lang>
|-
!firm
|firm || all ''meek'' then uniting ▼
||
*Operands of formulas as "~" in:<lang algol68>OP: ~ * ~</lang>
*Parameters of transput calls
|| e.g. <lang algol68>UNION(INT,REAL) var := 1</lang>
|-
|| all ''firm'' followed by widening, rowing or voiding▼
||Right hand side of:
* Identity-declarations, as "~" in: <lang algol68>REAL x =
* Initialisations, as "~" in: <lang algol68>REAL x := ~</lang>
Also:
* Actual-parameters of calls, as "~" in:<lang algol68>PROC: sin(~)</lang>
* Enclosed clauses of casts, as "~" in: <lang algol68>REAL(~)</lang>
* Units of routine-texts
* Statements yielding VOID
* All parts (but one) of a balanced clause
* One side of an identity relation, as "~" in: <lang algol68> ~ IS ~</lang>
||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:
<lang algol68>INT to LONG INT
|