(...in progress...)
Overview
Delta is a prototype-based object-oriented language. It uses differential inheritance, much like Io. In fact, you could say it's like Io except for the following differences:
- different syntax for method calls and blocks (see below)
- no operator precedence rules; in fact, there are no operators, just methods
- Scheme-like namespace (as opposed to Io's object-based namespaces); namespaces are first-class and can (and will) be manipulated by programs
An example
Let's look at a simple example. The following code runs the same code 1000 times and times how long it takes.
-- timeit.dx
t1 <- current-milliseconds:.
loop: 1000 { 3 plus: 4 }.
t2 <- current-milliseconds:.
t2 minus: t1 print:.
Delta has comments like Ada and Haskell: everything after "--" until end of line is ignored.
current-milliseconds: is a method call. Or actually it's more like a function call; current-milliseconds is a function in the builtin namespace. Function/method call syntax is foo: followed by zero or more arguments.
t1 <- ... is the assignment syntax. This is really syntactic sugar, and could be done by straight method calls that manipulate the current namespace, but this is not recommended. (The idea is that we can do as much as possible with a minimum of syntax, but for commonly used idioms it's a good idea to have a custom notation, to make things shorter and more readable.)
A statement ends in a dot. In some cases this can be omitted, like before a right parenthesis or a "}".
loop: is another builtin function that takes two arguments: a number (the number of times we loop) and a block containing the code to be executed. Blocks are a key concept in Delta; their syntax is simple, consisting of { ... } with zero or more statements in between.
3 plus: 4 is the Delta equivalent of 3 + 4 in most other languages. Delta does not have operators, nor does it have operator precedence rules (unlike Io). All it has is methods, and so we can add 3 and 4 by calling the plus method on 3. It takes getting used to, but it does make the syntax much more regular.
t2 minus: t1 print:. shows that method calls can be chained. This is one statement, consisting of a method call chain; we start with t2, call minus on it with argument t1, then we take the result of that method call, and call print on it. If Python objects had a print() method, the equivalent code would be (t2 - t1).print().
Blocks, functions and methods
The { ... } syntax creates a block object. Blocks are basically pieces of code, associated with a namespace (viz. the namespace in which the block was defined). Unlike e.g. Ruby, they do not take arguments.
Functions and methods are not all that different in Delta. They consist of a block and a number of parameters. Methods live in an object's namespace and are called through the object (which can be referred to inside the method body; in many languages this would be called this or self; in Delta we use the "~" symbol). Functions live in a regular namespace and are not associated with an object (and have no notion of "self"). Other than that, they're the same, and (much like Python) you can extract methods from objects and call them as functions, or stick functions into objects and use them as methods.
Blocks can be executed as well, in arbitrary namespaces; this allows us to write constructs in Delta that would require special syntax in most other languages, like loops and conditionals. It would also allow for macro-like facilities.
Symbols and namespaces
n <- 0.
{ n less-than: 10 } while-true: {
update: #n (n plus: 1).
n print:.
}.
"All done!" print:.
...
Forthcoming
- The current implementation of Delta is written in Chicken Scheme. While flexible, it is unfortunately extremely slow, even when compiled. I am thinking of writing a new reference implementation in OCaml. This will still be slow, as it's going to be an interpreter, but it should be faster and cleaner than the current version. (Optimistically, someday there will be a version that targets the JVM...)
- More syntactic sugar is desirable, e.g. for
update:and assignment to slots.