Changeset 92a0ee8
- Timestamp:
- Aug 7, 2024, 7:07:24 PM (4 months ago)
- Branches:
- master
- Children:
- b0069a3
- Parents:
- 4e09af2
- Location:
- doc/theses/jiada_liang_MMath
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/CFAenum.tex
r4e09af2 r92a0ee8 261 261 enum E2 e2 = C; 262 262 posn( e2 ); $\C[1.75in]{// 0}$ 263 enum E3 e3 = e2; 264 posn( e2 ); $\C{// 1 cost}$263 enum E3 e3 = e2; $\C{// Assignment with enumeration conversion E2 to E3}$ 264 posn( e2 ); $\C{// 1 }$ 265 265 void foo( E3 e ); 266 foo( e2 ); 267 posn( (E3)e2 ); $\C{// 1 cost}$268 E3 e31 = B; 269 posn( e31 ); $\C{// 0 cost}\CRT$266 foo( e2 ); $\C{// Type compatible with enumeration conversion E2 to E3}$ 267 posn( (E3)e2 ); $\C{// Explicit cast with enumeration conversion E2 to E3}$ 268 E3 e31 = B; $\C{// No conversion: E3.B}$ 269 posn( e31 ); $\C{// 0 }\CRT$ 270 270 \end{cfa} 271 271 The last expression is unambiguous. 272 While both @E2.B@ and @E3.B@ are valid candidates, @E2.B@ has an associated safe cost , so \CFA selects the zero cost candidate.272 While both @E2.B@ and @E3.B@ are valid candidates, @E2.B@ has an associated safe cost and @E3.B@ need not a conversion (@zero@ cost). \CFA selects the lowest cost candidate @E3.B@. 273 273 274 274 For the given function prototypes, the following calls are valid. … … 454 454 float ?[?]( float * arr, E2 index ) { return arr[ value( index ) ]; } 455 455 \end{cfa} 456 Wh en an enumeration type is being used as an array dimension, \CFA adds the enumeration type to the initializer's context.457 As a result, @H2@'s array destinators @A@, @B@ and @C@ are resolved unambiguously to type @E2@. 458 (@H1@'s destinators are also resolved unambiguously to @E1@ because @E2@ has a @value@ cost.) 459 456 While enumerator labels @A@, @B@ and @C@ are being defined twice in different enumerations, they are 457 unambiguous within the context. Designators in H1 are unambiguous becasue @E2@ has a @value@ cost to @int@, which 458 is more expensive than @safe@ cost from C-Enum @E1@ to @int@. On the hand, designators in @H2@ are resolved as @E2@ because 459 when a \CFA enumeration type is being used as an array dimension, \CFA adds the enumeration type to the initializer's resolution context. 460 460 461 461 \section{I/O} 462 463 As seen in multiple examples, enumerations can be printed and the default property printed is the enumerator's label, which is similar in other programming languages. 462 As seen in multiple examples, \CFA enumerations can be printed and the default property printed is the enumerator's label, which is similar in other programming languages. 464 463 However, very few programming languages provide a mechanism to read in enumerator values. 465 464 Even the @boolean@ type in many languages does not have a mechanism for input using the enumerators @true@ or @false@. -
doc/theses/jiada_liang_MMath/trait.tex
r4e09af2 r92a0ee8 164 164 \end{cfa} 165 165 Function @fromInstance@ projects a @Bounded@ member to a number and @fromInt@ is the inverse. 166 Function @pred@ takes an enumerator and returns the previous enumerator, if there is one, in sequential order, and @succ@ returns the next enumerator. 166 Function @pred@ and @succ@ are advancement functions: 167 @pred@ takes an enumerator and returns the previous enumerator, if there is one, in sequential order, and @succ@ returns the next enumerator. 167 168 \begin{cfa} 168 169 sout | fromInstance( Wed ) | fromInt( 2 ) | succ( Wed ) | pred( Wed );
Note: See TracChangeset
for help on using the changeset viewer.