26 Feb, 2009, Silenus wrote in the 1st comment:
Votes: 0

I decided it might be meaningful to make a post of my language design so that I might perhaps be able to get some comments. I will describe it in terms of FluffOS LPC because that is the language which it is the closest relative of. The main differences are in the type system but there are other differences which have been inspired by ML. Here is a description of the differences-

Types: struct-like class type removed has been removed. In it's place are three new types tuples, records & classes. records are essentially a struct type with a slightly different syntax and different initialization via a record constructor(discussed below). The class type is similar to what you have in java and can include methods and the tuple type is a finite list of elements which can be of fixed but different types. Functions can also be typed unlike FluffOS lpc functions. Type expressions are also support like int | string x; There is also a special reserved type Null or nothing type;

Type declarations(not yet finalized). int float and string are the same as current LPC others-:

Arrays- e.g. private [int] x;
Function- e.g. (int n) -> int f;
Mappings- e.g. private {string : int } y;
Record- e.g. private ( string : name, int : hp );
Tuple- e.g. private ( string, int, float, int );

You can create user defined types by assigning labels to the type declarators above using the keyword "def":

def Address = ( string : name, string: street, string: city );

These labels can be used to construct recursive types as well. The class type has special status and cannot be anonymous and is defined thus :

def MyRoom : Room {
private int roomno; private string short_description; private string long_description;
fact(int n) -> int { return n == 1 ? 1 : n*fact(n-1); }

Type parameters are also possible in both function and variable definitions:

def Stack<X> { }

and with methods inside a class scope:

private filter<X>( [X] arr, (X) -> int f ) -> [X] { … }

The remaining syntax remains close to LPC. There is however one additional construct for pattern matching which applies to switch statements and methods(still tentative).


private fact(int n) -> int
case 1 : { return 1; }
case n : { return n*fact(n-1); }

(for switches this is similar). Pattern matching can be quite elaborate [ head : tail ] is legal and you can peer into nested structures like tuples , type expressions and records. like with switches default : also works.

Types in this system are generally transparent. i.e. defined by their structure.

def A = (int,int)

def B = (int,int)

B b; A a; a = b; // this is legal

However you can force it to use name based semantics (using #) as well:

def #A = …
def B = …

B b; A a; a = b; // gives an error.

This language design is still a bit in flux which is why I am posting this to see what ppl. think. As for applies I am thinking perhaps of having the following for the master object-

resolve_path() // returns the path to a file in the file system
resolve_class() // returns the valid symbolic path (aka like java) given a symbol path.
compile_unit() // called when a class is compiled with the code representing the unit.
new_object() // allows for custom behavior when a request is made to create an object.
process_error() // for handling compile time and runtime error messages
inherit_class() // returns the class to inherit given a symbolic path.

Similar to dgd it will have a base class inherited by all classes without parents this is where you will stick in simul-efuns and the like. Whew (long post). Anyone have any thoughts?
27 Feb, 2009, elanthis wrote in the 2nd comment:
Votes: 0
I don't do LPC, so maybe it's more obvious to others, but… what's the 'private' do outside of def blocks? Is that for making it local to the scope/file?
27 Feb, 2009, Silenus wrote in the 3rd comment:
Votes: 0
Hopefully not to confuse anyone but LPC lacks def blocks of this type. I.e. the file itself is the "class" and is headed up by statements like:

inherit "/lib/room"; // has to be a constant string

followed by stuff like-

private int blah;

public void foo() { …. }


To generate an object from a class depending on the LPC dialect you either do something like new( "/lib/room" ); or clone_object( find_object("/lib/room") ); (Pike's syntax might be a bit different).

The reason I had to introduce def blocks was to get recursive typing and for now I am disallowing the use of methods / fields outside of def blocks. The reason I am posting this is I am trying to get it to be closer to LPC if possible while having a rational syntax.

some thoughts include- pike style declarations:

i.e. private array(int) x;
private mapping(string:int) y;
private record(string:name, int: hp) blah;

etc. (which would be more in keeping with LPC). Getting rid of the special class "def" syntax or reintroducing the inherit syntax (making the file essentially a class again).