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.
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).
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
`:: name arg1 arg2 body
selfin other programming languages.
name(i.e., a name with no punctuation)
= name value
+:: classname arg1 arg2
`:: method object arg1 arg2
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).
_ is defined by your program, and is instantiated when the program starts; the constructor for
_ is similar to
main in other programming languages.
Interpreter written in Python (download and run); View interpreter source