Zef Programming Language
Zef is a dynamically typed object oriented and functional programming language developed primarily to demonstrate language implementation technique.
Key Features
Simple Dynamic Types. Variables and fields do not have static type. All dynamic types are subclasses of Object. int and double are objects. Integers and doubles are both are 64-bit. null is a synonym for 0. false is a synonym for 0. true is a synonym for 1.
Classes. Zef's class system is most like Ruby's. Fields are private to their instance, except when exposed via accessors.
Closures. Classes and functions can be nested to any depth and doing so creates closures. For example, the member functions of a class nested in a function can see the outer function's local variables.
No Funny Business. Zef differs from other dynamic languages in that it lacks eval and has no monkey patching facilities. The closest thing to eval is load, which loads a source file; however the code in that file runs in its own scope. Classes statically declare their fields; new fields cannot be added dynamically. It's not possible to dynamically add fields to objects or to change object types.
Packages. Classes and functions can be nested in packages, making them globally visible to anyone who names or imports the package.
Garbage Collection. Allocate what you want. The GC cleans it up for you.
Example Program
class Foo {
# instance field with getter
readable x
# constructor
fn (inX) x = inX
# Operator overloading by name
fn add(y) Foo(x.toString + " " + y.toString)
# Overloading to-string conversion
fn toString x
}
# Prints "hello world" and then a newline
println(Foo("hello") + Foo("world"))
Download
Zef is hosted on GitHub. If you want full funcionality, you'll want to build it with Fil-C++ (otherwise you won't get GC).
Why?
Zef was created by Fil Pizlo as a side quest for the love of the game.
Also:
Zef was implemented in Fil-C++ as a testing/dogfooding exercise.
Fil optimized Zef and documented the journey, which might be useful to folks who want to write high performance dynamic language interpreters.