Proposed additions to classes INTEGER_GENERAL and CHARACTER_GENERAL

by Colin Adams (modified: 2007 Mar 09)

Following an article by Roger Osmond Auto-Increment_Proposal, I propose the following additions.

To both classes INTEGER_GENERAL and CHARACTER_GENERAL, add features successor and predecessor, both queries returning like Current.

Successor should return an INTEGER whose code is one greater than Current (it must have a pre-condition that code is not the maximum possible for the particular descendant of INTEGER_GENERAL). In CHARACTER_GENERAL, this will return the next character in the Unicode code-point collation (a similar pre-condition is necessary to avoid return a character with code greater than the maximum for the concrete descendant class - in the case of CHARACTER_32, that is the maximum Unicode code-point permitted, NOT the maximum value for INTEGER_32).

Predecessor is the reverse operation, and has the corresponding opposite pre-condition.

For characters, the concept of the next and previous character is really a property of a collation. So ST_COLLATOR (or equivalent classes) and its descendants could be enhanced to add next_character and previous_character.

In class INTEGER_GENERAL only, add mutator routines increment and decrement, with prefix aliases of ++ and -- respectively (I can't say I really care for these prefix operators, but they won't do any harm). These routines respectively add and subtract 1 from Current. They will have pre-conditions to avoid overflow/wrap-around effects.

Comments
  • Peter Gummer (17 years ago 11/3/2007)

    Alias Validity Rule

    The prefix operator idea won't work, because it violates the Alias Validity Rule. See 8. 5. 26 in the ECMA spec.

    This throws a big spanner in the works for Roger Osmond's objective of making Eiffel more palatable to C punctuation junkies. Sorry, Roger.