正在加载图片...
$18.5 CONSTANTS OF STRING TYPE 653 will try to access a non-existent field in an object of type A. The problem is that anchoring causes an implicit redefinition.Had/been explicitly redefined,through a declaration appearing in B under the form f:B is once !Result.make end assuming that the original in class 4 similarly returned a result of type 4(rather than like Current),then we would not have any trouble:direct instances of 4 use the A version, direct instances of B use the B version.Anchoring,of course,was introduced precisely to rid us of such explicit redefinitions serving type needs only. These two cases are evidence of incompatibilities between the semantics of once functions(procedures are fine)and the results of either anchored or formal generic types One way out,suggested by the last observation on implicit vs.explicit redefinition, would be to treat such cases as we would explicit redefinitions:to specify that the result of a once function will be shared only within each generic derivation of a generic class, and,if the result is anchored,only within the direct instances of the class.The disadvantage of this solution,however,is that it goes against the expected semantics of once functions,which from a client's viewpoint should be the conceptual equivalent of a shared attribute.To avoid confusionand possible errors it seems preferable to take a more draconian attitude by banning such cases altogether: Once Function rule The result type ofa once function may not be anchored,and may not involve any formal generic parameter. 18.5 CONSTANTS OF STRING TYPE The beginning of this chapter introduced character constants,whose value is a single character.The example was Backslash:CHARACTER is'' Often,classes will also need symbolic constants representing multi-character strings.The notation for manifest string constants will use double quotes: [S1] Message:STRING is "Syntax error" Recall that STR/NG is a class of the library,not a simple type.So the value associated at run time with an entity such as Message is an object(an instance of STR/NG).As you may have guessed,the above declaration is a shorthand for the declaration of a once function,here of the form:§18.5 CONSTANTS OF STRING TYPE 653 will try to access a non-existent field in an object of type A. The problem is that anchoring causes an implicit redefinition. Had f been explicitly redefined, through a declaration appearing in B under the form f: B is once !! Result ● make end assuming that the original in class A similarly returned a result of type A (rather than like Current), then we would not have any trouble: direct instances of A use the A version, direct instances of B use the B version. Anchoring, of course, was introduced precisely to rid us of such explicit redefinitions serving type needs only. These two cases are evidence of incompatibilities between the semantics of once functions (procedures are fine) and the results of either anchored or formal generic types. One way out, suggested by the last observation on implicit vs. explicit redefinition, would be to treat such cases as we would explicit redefinitions: to specify that the result of a once function will be shared only within each generic derivation of a generic class, and, if the result is anchored, only within the direct instances of the class. The disadvantage of this solution, however, is that it goes against the expected semantics of once functions, which from a client’s viewpoint should be the conceptual equivalent of a shared attribute. To avoid confusion and possible errors it seems preferable to take a more draconian attitude by banning such cases altogether: 18.5 CONSTANTS OF STRING TYPE The beginning of this chapter introduced character constants, whose value is a single character. The example was Backslash: CHARACTER is '\' Often, classes will also need symbolic constants representing multi-character strings.The notation for manifest string constants will use double quotes: [S1] Message: STRING is "Syntax error" Recall that STRING is a class of the library, not a simple type. So the value associated at run time with an entity such as Message is an object (an instance of STRING). As you may have guessed, the above declaration is a shorthand for the declaration of a once function, here of the form: Once Function rule The result type of a once function may not be anchored, and may not involve any formal generic parameter
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有