Unoop 2.1

Unoop was an attempt to make for object-oriented programming what Unlambda is for functional programming. I'm not sure if I succeeded, but here is my attempt.

General program format

A program consists of some number of class declarations, as described in the next section. Whitespace (including newlines) may appear almost anywhere in the program, and is ignored (and not required). Comments start with # and continue until the end of the line. The current version of the interpreter does not allow comments directly before colons.

Identifiers consist of any number of dollars signs followed by a letter (case-sensitive), digit, underscore (_), or at sign (@). Class names, method names, instance variable names, and argument names each have a separate namespace.

In all syntactic constructs explained below, if there are colons, there can be any number of colons (including zero).

Declarations

At the top level of the program are class definitions. A class definition consists of the name of the class, followed directly by the name of the superclass and then zero or more constructor and/or method definitions. The class definition ends when the next one begins. Constructors and methods are defined as follows:

+:: arg1 arg2 +:: superarg1 superarg2 body
Define a constructor. The number of colons in the first group of colons indicates the number of arguments that the constructor takes (zero or more); constructors with different numbers of arguments are considered distinct. The number of colons in the second group of colons indicates the number of arguments to pass to the superclass's constructor (zero or more). The body is a single expression. Constructors are inherited by subclasses.
`:: name arg1 arg2 body
Define a method. The number of colons indicates the number of arguments that the method takes; methods with the same name but different numbers of arguments are considered distinct. The body is a single expression.

Expressions

.
The current object (i.e., the one this method was called on). Similar to this or self in other programming languages.
name (i.e., a name with no punctuation)
An argument to the current method. Arguments cannot be changed within the method.
?name
An instance variable of the current object. There is no way to access instance variables of other objects directly.
= name value
Changes the value of an instance variable in the current object. The question mark should not appear before the name; it is only used when reading the value of the variable.
+:: classname arg1 arg2
Creates an instance of the specified class and calls its constructor. The number of colons indicates the number of arguments to pass to the constructor.
`:: method object arg1 arg2
Calls a method on a specified object. The number of colons indicates the number of arguments to pass to the method. Note that, unlike many object-oriented languages, the name of the method comes before the object.

Special classes

The class 0 (zero) exists already as a class that you can use as a superclass of objects that don't need a more specific superclass (since every object must have a superclass), similar to Java's Object class. It has two methods: @, which reads a character from the standard input and returns it, and Q, which quits the program.

Character classes, whose names are ' followed by any character (including whitespace or newlines), cannot be instantiated directly. To use them, you must either subclass them, or get them from @. In addition to the methods of 0, these have a p method, which prints the character, and a ::q method that tests whether the current character is the same as the last character read with @, and returns its first argument if it is and its second argument if it's not. To define a character indicating the end of a file, put the ' at the end of the file (and make sure that your editor doesn't add an extra newline).

The class _ is defined by your program, and is instantiated when the program starts; the constructor for _ is similar to main in other programming languages.

Interpreters

Interpreter written in Python (download and run); View interpreter source