Changes in / [9d3a4cc:b0069a30]
- Location:
- doc/theses/jiada_liang_MMath
- Files:
-
- 2 edited
-
CFAenum.tex (modified) (2 diffs)
-
trait.tex (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/CFAenum.tex
r9d3a4cc rb0069a30 262 262 enum E2 e2 = C; 263 263 posn( e2 ); $\C[1.75in]{// 0}$ 264 enum E3 e3 = e2; 265 posn( e2 ); $\C{// 1 cost}$264 enum E3 e3 = e2; $\C{// Assignment with enumeration conversion E2 to E3}$ 265 posn( e2 ); $\C{// 1 }$ 266 266 void foo( E3 e ); 267 foo( e2 ); 268 posn( (E3)e2 ); $\C{// 1 cost}$269 E3 e31 = B; 270 posn( e31 ); $\C{// 0 cost}\CRT$267 foo( e2 ); $\C{// Type compatible with enumeration conversion E2 to E3}$ 268 posn( (E3)e2 ); $\C{// Explicit cast with enumeration conversion E2 to E3}$ 269 E3 e31 = B; $\C{// No conversion: E3.B}$ 270 posn( e31 ); $\C{// 0 }\CRT$ 271 271 \end{cfa} 272 272 The last expression is unambiguous. 273 While both @E2.B@ and @E3.B@ are valid candidates, @E2.B@ has an associated safe cost , so \CFA selects the zero cost candidate.273 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@. 274 274 275 275 For the given function prototypes, the following calls are valid. … … 455 455 float ?[?]( float * arr, E2 index ) { return arr[ value( index ) ]; } 456 456 \end{cfa} 457 Wh en an enumeration type is being used as an array dimension, \CFA adds the enumeration type to the initializer's context.458 As a result, @H2@'s array destinators @A@, @B@ and @C@ are resolved unambiguously to type @E2@. 459 (@H1@'s destinators are also resolved unambiguously to @E1@ because @E2@ has a @value@ cost.) 460 457 While enumerator labels @A@, @B@ and @C@ are being defined twice in different enumerations, they are 458 unambiguous within the context. Designators in H1 are unambiguous becasue @E2@ has a @value@ cost to @int@, which 459 is more expensive than @safe@ cost from C-Enum @E1@ to @int@. On the hand, designators in @H2@ are resolved as @E2@ because 460 when a \CFA enumeration type is being used as an array dimension, \CFA adds the enumeration type to the initializer's resolution context. 461 461 462 462 \section{I/O} 463 464 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. 463 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. 465 464 However, very few programming languages provide a mechanism to read in enumerator values. 466 465 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
r9d3a4cc rb0069a30 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.