26 Aug 2001 emk   » (Master)

My Favorite Toy Language. Oh, dear. My design efforts have gotten too far ahead of my coding efforts, opening me to charges of bogosity. :-/ An overview of what I'm up to...

Soft Typing. MFTL is softly typed. This means that (1) everything, including primitive types, is a subclass of Object, (2) type declarations all default to Object and (3) downcasting is automatic. For example, the following program is legal:

def fact_untyped (i)
  if (i <= 1)
    1
  else
    i * fact_untyped(i-1)
  end
end

But if the programmer types the following, they get much better performance and compile-time warnings about type violations:

def fact_untyped (i: int): int
  if (i <= 1)
    1
  else
    i * fact_untyped(i-1)
  end
end
Everything's An Expression. In the above example, 'if' is an expression, like the ternary operator in C. So you could write:
var x = if (y) 1 else 2 end

Newlines End Statements. Just like in sh, bash, JavaScript, and Ruby, newlines in MFTL are statement terminators. (This is slightly funky, but it allows 'if' to be an expression without massively cruftifying the semicolon-placement rules.)

Keyword-Based Initialization. Classes generally don't need constructors:

class Sample ()
  var x, key: x
  var y = 10
end
s = new(Sample, x: 5)

Generic Functions. You can do the equivalent of operator-overloading at run time, not just compile time.

abstract class Thing () end
class Rock (Thing) end
class Paper (Thing) end
class Scissors (Thing) end
def defeats? (a: Thing, b: Thing) false end
def defeats? (a: Paper, b: Rock) true end
def defeats? (a: Rock, b: Scissors) true end
def defeats? (a: Scissors, b: Paper) true end
defeats?(new(Paper), new(Scissors)) // false
defeats?(new(Rock), new(Scissors))  // true

Yes, we know how to make this go fast.

Getters and Setters. No more endless 'getFoo' and 'setFoo' functions! Just write:

public class Example ()
  public var foo, key: foo
end

If you later decide that you need a getter and setter function, just write:

public class Example ()
  var real_foo, key: foo
  public def get foo ()
    real_foo
  end
  public def set foo (value)
    real_foo = value
  end
end
The users of the class will never know the difference.

Other Stuff. Things I want, but which I know will require extra work to do right: inlineable iterators, design by contract, integrated unit tests, simple templates.

Performance. With full type declarations, it should be possile to compile MFTL to run at speeds approaching that of C. Softly-typed languages are a solved problem.

Implementation Status. The parser and the VM are about 50% complete. The compiler was about 2% complete before I threw it out and started over. :-( If I had the luxury of working on this project full-time, I could ship a demo interpreter in about three months, and an MFTL-to-C compiler not long after.

Feedback. Comments, suggestions to eric.kidd@pobox.com.

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!