class interface Integer is
====================================================
== Author: Michael Kölling
== Version: 1.0
== Date: 9 October 1996
== Short: Blue standard Integer class
==
== "Integer" is a standard class of the Blue language. It is used to store
== integer numbers. "Integer" is predefined in Blue and thus does not
== have to be imported (i.e. explicitly listed in the "uses" clause). It
== is automatically known in all classes.
==
== User defined classes cannot inherit from "Integer".
==
====================================================
routines
neg -> (result: Integer) is
== Return the negative value of this number.
== Alias: - (prefix) (e.g. -4)
add (other: Integer) -> (sum: Integer) is
== Return the sum of this number and the number other.
== Alias: + other (e.g. 3 + 4)
sub (other: Integer) -> (diff: Integer) is
== Return the difference of this number and the number other.
== Alias: - other (e.g. 3 - 4)
mult (other: Integer) -> (prod: Integer) is
== Return the product of this number and the number other.
== Alias: * other (e.g. 3 * 4)
div (other: Integer) -> (quot: Integer) is
== Return the integer part of the quotient of this number and other.
== Alias: div other (e.g. 3 div 4)
mod (other: Integer) -> (rem: Integer) is
== Return the remainder of the integer division of this number and
== other.
== Alias: mod other (e.g. 3 mod 4)
pow (exp: Integer) -> (result: Integer) is
== Return this number raised to the power specified by exp.
== Alias: ^ other (e.g. 3 ^ 4)
greater (other: Integer) -> (result: Boolean) is
== Return true if this number is greater than other, otherwise false.
== Alias: > other (e.g. 3 > 4)
greaterEq (other: Integer) -> (result: Boolean) is
== Return true if this number is greater or equal than other, otherwise
==false.
== Alias: >= other (e.g. 3 >= 4)
less (other: Integer) -> (result: Boolean) is
== Return true if this number is less than other, otherwise false.
== Alias: < other (e.g. 3 < 4)
lessEq (other: Integer) -> (result: Boolean) is
== Return true if this number is less or equal than other, otherwise
== false.
== Alias: <= other (e.g. 3 <= 4)
toString -> (s: String) is
== Return a string representation of this number. The standard format
== object (of class OutputFormat) is used to determine details of the
== appearance.
== Alias: str ()
class interface Real is
====================================================
== Author: Michael Kölling
== Version: 1.0
== Date: 9 October 1996
== Short: Blue standard Real class
==
== "Real" is a standard class of the Blue language. It is used to store
== floating point numbers. "Real" is predefined in Blue and thus does not
== have to be imported (i.e. explicitly listed in the "uses" clause). It
== is automatically known in all classes.
==
== User defined classes cannot inherit from "Real".
==
====================================================
creation
== Never used explicitly. "Real" is a manifest class, and all
== real values exist automatically during every execution.
== No further reals can be created at runtime.
routines
neg -> (res: Real)
== Negation. Return the real that represents the value
== "-this".
== Alias: -
post
res <> nil
add (other: Real) -> (res: Real)
== Addition. Return the real that represents the value
== "this + other".
== Alias: +
pre
other <> nil
post
res <> nil
sub (other: Real) -> (res: Real)
== Subtraction. Return the real that represents the value
== "this - other".
== Alias: -
pre
other <> nil
post
res <> nil
mult (other: Real) -> (res: Real)
== Multiplication. Return the real that represents the value
== "this * other".
== Alias: *
pre
other <> nil
post
res <> nil
divide (other: Real) -> (res: Real)
== Division. Return the real that represents the value
== "this / other".
== Alias: /
pre
other <> nil and
other <> 0.0
post
res <> nil
power (n: Real) -> (res: Real)
== Power. Return the real that is represents the value
== "this ^ n" ("this to the power of n").
== Alias: ^
pre
n <> nil
post
res <> nil
sqrt -> (res: Real)
== Square root. Return the real that is represents the value
== "sqrt (this)" ("square root of this").
post
res <> nil
trunc -> (res: Integer)
== Truncate to integer. Return the integer that is represents the
== whole number part of this number (i.e. "this" is rounded towards
== zero).
post
res <> nil
round -> (res: Integer)
== Round to integer. Return the integer that is nearest to the
== value of "this". (Fractions of value 0.5 or greater will be
== rounded away from zero, fractions less than 0.5 will be rounded
== towards zero.)
post
res <> nil
greater (other: Real) -> (res: Boolean)
== Greater than. Return true if the value of this real is greater
== than the value of "other". Return false otherwise.
== Alias: >
pre
other <> nil
post
res <> nil
greaterEq (other: Real) -> (res: Boolean)
== Greater or equal. Return true if the value of this real is
== greater than or equal to the value of "other". Return false
== otherwise.
== Alias: >=
pre
other <> nil
post
res <> nil
less (other: Real) -> (res: Boolean)
== Less than. Return true if the value of this real is less
== than the value of "other". Return false otherwise.
== Alias: <
pre
other <> nil
post
res <> nil
lessEq (other: Real) -> (res: Boolean)
== Less or equal. Return true if the value of this real is
== less than or equal to the value of "other". Return false
== otherwise.
== Alias: <=
pre
other <> nil
post
res <> nil
toString -> (s: String)
== Conversion to String. Returns a string with a printable
== representation of this real number.
== Alias: str ()
post
s <> nil
class interface Boolean is
====================================================
== Author: Michael Kölling
== Version: 1.0
== Date: 8 October 1996
== Short: Blue standard Boolean class
==
== "Boolean" is a standard class of the Blue language. It is used to store
== truth values ("true" and "false"). "Boolean" is predefined in Blue and
== thus does not have to be imported (i.e. explicitly listed in the "uses"
== clause). It is automatically known in all classes.
==
== User defined classes cannot inherit from "Boolean".
==
====================================================
creation
== Never used explicitly. "Boolean" is a manifest class, and the
== boolean values exist automatically during every execution.
== No further boolean values can be created at runtime.
routines
invert -> (res: Boolean)
== Negation. Return "not this", i.e. "false" if this is "true",
== or "true" if this is "false".
== Alias: not
post
res <> nil
and (other: Boolean) -> (res: Boolean)
== Logical and. Return the boolean value "this and other".
== Alias: and
pre
other <> nil
post
res <> nil
or (other: Boolean) -> (res: Boolean)
== Logical or (inclusive). Return the boolean value
== "this or other".
== Alias: or
pre
other <> nil
post
res <> nil
toString -> (s: String)
== Conversion to String. Returns a string with a printable
== representation of this boolean value. The string returned is
== "true" for true and "false" for false.
== Alias: str ()
post
s <> nil
class interface String is
===================================================
== Author: Michael Kölling
== Version: 1.0
== Date: 24.9.96
== Short: Blue standard String class
==
== This class implements the standard String type for Blue.
== Strings are a sequence of characters. The first character in a string
== has the index 1, the last index is equal to length(string).
==
== Blue does not have a separate character type. Characters are represented
== by a string of length 1.
==
===================================================
creation is
== Never used - strings are created by writing string literals
== in double quotes.
== Example: "This is a string"
routines
length -> (l: Integer) is
== Return the length of the string (number of characters).
concat (s: String) -> (newstring: String) is
== Return the string which is the concatenation of this string
== and 's'. This string and 's' remain unchanged.
== Alias: str ()
substring (start: Integer, len: Integer) -> (s: String) is
== Return the substring from this string which starts at 'start'
== with length 'len'.
== If "len" is nil, the substring from "start" to the end of the
== string is returned.
pre
(start >= 1) and (start <= length)
and
(len <> nil => (start+len <= length+1))
find (s: String, n: Integer) -> (pos: Integer) is
== Return the position of 's' in this string, starting the search at
== 'n'. 'pos' is the index where 's' was found or nil if not found.
pre
(s <> nil) and (n >= 1) and (n <= length)
insert (s: String, pos: Integer) -> (newstring: String) is
== Return a string that is like this string with 's' inserted into this
== string at position 'pos'.
pre
(s <> nil) and (pos >= 1) and (pos <= length)
delete (start: Integer, cnt: Integer) -> (newstring: String) is
== Return a string that is like this string with 'cnt' characters deleted,
== starting at position 'start'.
== If "cnt" is nil, all characters from "start" to the end of the
== string are deleted.
pre
(start >= 1) and (cnt >= 0) and (cnt <= length)
less (s: String) -> (is_less: Boolean) is
== Returns true, if this string is less than 's', else false.
== See class comment (above) for ordering of strings.
== Alias: <
pre
s <> nil
greater (s: String) -> (is_greater: Boolean) is
== Returns true, if this string is greater than 's', else false.
== See class comment (above) for ordering of strings.
== Alias: >
pre
s <> nil
lessEq (s: String) -> (is_less_eq: Boolean) is
== Returns true, if this string is less or equal to 's', else
== false.
== See class comment (above) for ordering of strings.
== Alias: <=
pre
s <> nil
greaterEq (s: String) -> (is_greater_eq: Boolean) is
== Returns true, if this string is greater or equal to 's', else
== false.
== See class comment (above) for ordering of strings.
== Alias: >=
pre
s <> nil
toString -> (s: String)
== Conversion to String. This function returns the string itself.
== It is an identity function. There is usually no need to call
== this function explicitly. It is provided to make the "str()"
== alias work with all standard classes, including string.
== Alias: str ()
post
s <> nil
toUpper -> (s: String)
== Return a string that is a copy of this string with all lower case
== letters replaced by their upper case equivalent. Other character are
== unchanged.
toLower -> (s: String)
== Return a string that is a copy of this string with all upper case
== letters replaced by their lower case equivalent. Other character are
== unchanged.
strip -> (s: String)
== Return a string that is a copy of this string with leadfing and
== trailing whitespace removed. Whitespace are spaces, TAB
== characters ("\t") and newlines ("\n").
caseEqual (other: String) -> (is_equal: Boolean)
== "caseEqual" is a case-insensitive string equality test.
== It returns true, if this string and "other" are equal except
== for possible differences in the case of letters.
ord -> (val: Integer)
== Return the ordinal value of the first character of this string.
== The ordinal value of a character is its internal byte
== representation, usually its ASCII (or, more correctly ISO) code.
== If the length of the string is 0, the result is 0.
hash (limit: Integer) -> (hash_val: Integer)
== Return a hash value for a string. The value is between 0
== and limit.
pre
limit > 0
post
hash_val >= 0 and hash_val < limit
class interface Array <ELEM_TYPE> is
====================================================
== Author: Michael Kölling
== Version: 1.0
== Date: 14 November 1996
== Short: Blue standard Array class
==
== "Array" is a Blue standard class that is predefined in the Blue language.
== Array objects can be used to store a number of objects of the same type.
== Arrays are mainly a means for implementation of higher level collection
== classes (such as sets, sequences, lists, etc.) but they can also be used
== directly in user classes.
==
== Arrays are best used in situations where the number of elements is known
== in advance and does not change very often. Resizing an array can be
== relatively expensive in terms of both time and space required. If the
== number of elements changes regularly dynamically, consider using
== another collection (List, Set, etc.) from the standard collection library.
==
====================================================
creation (size: Integer)
== Creation an array with 'size' elements.
routines
getElem (pos: Integer) -> (elem: ELEM_TYPE)
== Return the element at position 'pos'.
pre
pos >= 1 and
pos <= size
putElem (pos: Integer, elem: ELEM_TYPE)
== Assign 'elem' to position 'pos'.
pre
pos >= 1 and
pos <= size
init (val: ELEM_TYPE)
== Set all array elements to 'val'.
size -> (sz: Integer)
== Return the current size of the array.
post
sz >= 0
setSize (sz: Integer)
== Set the size of the array to 'sz'. If the current size is larger
== the elements at positions greater than 'sz' will be lost. If the
== current size is smaller, the elements at the new positions will
== be undefined.
pre
sz >= 0
post
size = sz
class interface Enumeration is
===================================================
== Author: Michael Kölling
== Version: 1.0
== Date: 30.11.96
== Short: Abstract superclass for enumerations.
==
== This class serves as a superclass for all enumeration classes. It is
== abstract - no objects can be created of this class directly.
==
===================================================
routines
pred -> (previous: SelfType) is
== Return the predecessor in this enumeration type. If there is no
== predecessor, return nil.
succ -> (next: SelfType) is
== Return the successor in this enumeration type. If there is no
== successor, return nil.
ord -> (position: Integer) is
== Return the ordinal position of this element in the enumeration list.
== The first element has the ordinal 1, the next is 2, and so on.
toString -> (s: String) is
== Conversion to String. Returns the name of this enumeration value
== as a string
== Alias: str ()
end class
Note that "SelfType" is no legal type in Blue. A Blue class like this cannot normally be written. The meaning of the word "SelfType" in the routine interfaces above indicates that for every concrete subclass of Enumeration that routine returns the type of the subclass. For an Enumeration "Colour", for example, the routine pred returns a result of type Colour.
class interface TextTerminal is
====================================================
== Author: Michael Kölling
== Version: 1.0
== Date: July 1996
== Short: Standard text terminal for the Blue environment
==
== The TextTerminal provides a simple standard terminal for text I/O.
== Input and output is buffered by default. The output buffer is flushed
== at the end of each line (when a "\n" is written) and on a call of an
== input routine. If single characters have to be written, buffering
== can be switched off (see below).
====================================================
creation
== Create the TextTerminal
routines
write (s: String)
== Write 's' to the terminal
readstr -> (s: String)
== Read a string from the terminal. Reads characters until
== a line break ("\n") is read. The resulting string does
== not include the line break character.
readChar -> (s: String)
== Read the next character from the terminal. Every character
== (including line break characters) are returned as entered
== The line break character is returned as "\n".
== The input is buffered by default. (This means that editing the
== input line during input is possible for the user, and the program
== will return from this function only after a whole line was
== entered.) For unbuffered input, see getChar and askChar
== below.
readInt -> (i: Integer)
== Read an integer from the terminal. Skips white space (spaces,
== tabs and newlines) before the integer. Returns "nil" if the next
== non-white characters do not represent a number.
== Numbers are written with an optional - or + sign and digits.
readReal -> (r: Real)
== Not yet implemented
getChar -> (s: String)
== Get the next character from the terminal (unbuffered).
== This function is similar to "readChar" (see above), but the
== input is not buffered. The function returns as soon as a
== character is entered - no line editing is provided.
askChar -> (s: String)
== Check whether there is a character to be read from the terminal.
== If so, read it.
== This function is similar to "getChar" (see above), but the
== function always returns immediately. If a character has been
== entered, that character is returned, otherwise "nil" is returned.
show
== Show the terminal window.
== This routine opens the window if it was not open, de-iconifies
== the window if it was iconified and brings it to the top of the
== window stack.
hide
== Hide the terminal window. The window is closed.
clear
== Clear the terminal window and set the cursor to 0,0 (the upper
== left corner)
width -> (columns: Integer)
== Return the current width of the terminal window in characters.
== (Note that the terminal currently does not support resizing.)
height -> (lines: Integer)
== Return the current height of the terminal window in text lines.
== (Note that the terminal currently does not support resizing.)
cursorTo (x: Integer, y: Integer)
== Set the cursor to position (x,y). The legal ranges for
== x and y are:
== x: 0 .. width-1
== y: 0 .. heigth-1
== If x or y is outside its range, it is set to the nearest
== legal value.
== This routine works only after the terminal window has been
== exposed at least once (otherwise the terminal size is not known).
pre
x <> nil and y <> nil
cursorOn
== Switch the screen cursor on. (This is the default.)
cursorOff
== Switch the screen cursor off.
buffered (buf_on: Boolean)
== Set the output buffering mode. If buffering is on (the default)
== then the output line is buffered. The buffer is flushed when
== a newline is written or when an input routine is called.
== If output should be visible immediately without a newline, switch
== buffering off. Output without buffering is slower for most
== purposes.
pre
buf_on <> nil
end class