Animal := [new
health := 100.
[die
health <- 0.
|health
health]].
Cat := [new
[makeSound
console print: 'Meow!'.
| ...Animal new]].
Dog := [new
[makeSound
console print: 'Woof!'.
| ...Animal new]].
peppy := Cat new.
peppy makeSound. "This will print 'Meow!'"
console print: peppy health. "100"
A purely object-oriented toy language, demonstrating how OOP does not need inheritance, traditional classes or prototypes.
Imperative and sequential. You can:
- Define and mutate variables.
- Create an object by defining a set of method closures.
- While defining an object, copy in another object's methods. (Variable references are early-bound, i.e. no open recursion.)
- Create a block, an object with a single
do
method with special return semantics. - Perform an early return, exiting from the innermost lexical non-block method.
Operator precedence is not finalized, but is currently as follows:
- Unary messages have the highest precedence.
3 factorial + 4
means(3 factorial) + 4
. - Binary operators are next, and left-associative.
3 + 4 * 5 min: 2
means((3 + 4) * 5) min: 2
. - Keyword messages are last and also left-associative.
Expressions can be sequenced with .
, returning the value of the last expression evaluated.
Object literals are defined with []
enclosing a set of methods and decorations, separated by |
. A method consists of a method signature and a sequence of expressions. A decoration is defined with ...<expr>
.
A block can be defined with {}
and contains a single expression. An early return may be constructed with ^ <expr>
.
There are several objects built into the language.
- Numbers, strings and booleans implement a variety of operators. Strings can
import
the file with their name in the repository, e.g.'brainfuck' import
. - Booleans implement
if:
, sendingtrue
orfalse
. - The
console
canread
input,print:
orwrite:
output, or throw anerror:
. - The
Array
object can createnew
arrays, that can get valuesat:
a position, orat:Put:
. - The
system
canrequire:
tinytalk code oropen:
files. Files canread
lines,readAll
,write:
, get theirposition
andsize
,goto:
,move:
andclose
.