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 appliedavailable in this context !! Context location !! Coercion examples
|-
!soft
|soft || deproceduring
|| The LHS of assignments, as "~" in: <lang algol68>~ := ...</lang>
|soft || deproceduring
||
* 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>
|weak || all '''soft'' above' then weak dereferencing
||
<lang algol68>REF REF REF INTBOOL to REF INT</lang>BOOL
REF REF INT to REF INT
REF REF REF REAL to REF REAL
REF REF REF REF STRUCT to REF STRUCT</lang>
|-
|!meek
|| 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))
|| all '''weak'' above' then dereferencing
||
<lang algol68>REF REF REF REALBOOL to REAL</lang>BOOL
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
|firm || all '''meek''' then uniting
|| e.g. <lang algol68>UNION(INT,REAL) var := 1</lang>
|-
||!strong
|| all ''firm'' followed by widening, rowing or voiding
||Right hand side of:
* Identity-declarations, as "~" in: <lang algol68>REAL x =: ~</lang>
* 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>
|| all '''firm''' followed bythen widening, rowing orand voiding
||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