Classroom Object Oriented Language, aka Classroom Object Oriented Language, is a programming language created in 1996 by Alexander Aiken.
#669on PLDB | 28Years Old | 102Repos |
Cool, an acronym for Classroom Object Oriented Language, is a computer programming language designed by Alexander Aiken for use in an undergraduate compiler course project. While small enough for a one term project, Cool still has many of the features of modern programming languages, including objects, automatic memory management, strong static typing and simple reflection. The reference Cool compiler is written in C++, built fully on the public domain tools. Read more on Wikipedia...
class Main inherits IO {
main(): Object {
out_string("Hello World.\n")
};
};
(* This simple example of a list class is adapted from an example in the
Cool distribution. *)
class List {
isNil() : Bool { true };
head() : Int { { abort(); 0; } };
tail() : List { { abort(); self; } };
cons(i : Int) : List {
(new Cons).init(i, self)
};
};
class Cons inherits List {
car : Int; -- The element in this list cell
cdr : List; -- The rest of the list
isNil() : Bool { false };
head() : Int { car };
tail() : List { cdr };
init(i : Int, rest : List) : List {
{
car <- i;
cdr <- rest;
self;
}
};
};
class Main inherits IO {
main(): Object {{
out_string("Enter an integer greater-than or equal-to 0: ");
let input: Int <- in_int() in
if input < 0 then
out_string("ERROR: Number must be greater-than or equal-to 0\n")
else {
out_string("The factorial of ").out_int(input);
out_string(" is ").out_int(factorial(input));
out_string("\n");
}
fi;
}};
factorial(num: Int): Int {
if num = 0 then 1 else num * factorial(num - 1) fi
};
};
Feature | Supported | Example | Token |
---|---|---|---|
Booleans | ✓ | true false | |
MultiLine Comments | ✓ | (* A comment *) | (* *) |
Print() Debugging | ✓ | out_string | |
Comments | ✓ | -- A comment | |
Line Comments | ✓ | -- A comment | -- |
Semantic Indentation | X |