digitalmars.D - Vault language
- bearophile (37/40) Nov 05 2008 Seeing people discuss about Cyclone, I think I can show the Vault langua...
Seeing people discuss about Cyclone, I think I can show the Vault language too, that has similar purposes (that is of being safer than C): http://research.microsoft.com/vault/ It's quite C-based, but it looks a bit higher-level than Cyclone. It has some interesting features. Here are few of them as I read from the site, I haven't tried this language. Some parts of the site look unfinished from year 2001 so this looks like a dead site/language. It has types int8 int16 int32 int64 float32 float64, and also it has int that is as long as the CPU word. This is similar to my proposal, but I have suggested to use the number of bytes intead of bits.In its simplest form, Vault's switch statement is like that in C, with one exception: each case within the switch must end with a break, continue, or return statement; Vault does not allow "fall through" between cases like C does. Vault also has a more powerful form of switch statements, which supports pattern matching.<In C, structures are not indirect by default; to create an indirection to a structure, a programmer declares a pointer to a structure. Vault reverses this: by default, a structure is indirect; to prevent having an indirection on a structure, a programmer declares the structure as "flat".struct Foo { int i; } flat Foo f1; // flat, it's a value flat Foo f2; // it's a reference to Foo <In C, a variable of type struct outer* could either point to a valid structure or could be NULL; whereas, in Vault, a variable of type outer always points to a valid structure. For a Vault programmer to declare that an indirection can potentially be NULL, she uses the question mark suffix:outer? x = NULL; outer y = NULL; // illegal without the ? suffix < So it seems structs in Vault can be both like the current D ones, or by a reference that can't be null like Walter has recently talked about. This adds a little of complexity to the language, but covers both situations. Vault has built-in automatically tagged unions, named "variants" here. This C-like code: struct mon { enum { Id, Name } tag; union { int id; char *name; } data; } Can be written like this in Variant: variant moniker [ `Id(int) | `Name(string) ] ; Such variant types can be used to represent tree structures too (this is a bit like the very useful algebraic types of functional languages like Haskell and Scala): variant intTree [ `Empty | `Tree(int, intTree, intTree) ]; Later you can define an actual tree like this: intTree t = `Tree(5, `Tree(2, `Empty, `Empty), `Tree(8, `Tree(6, `Empty, `Empty), `Tree(11, `Empty, `Empty))); Switch statements also support variant values and a little of pattern matching (you can also give a name to the sub-patterns, but the flexibility of such syntax is limited), for example: switch (n+m, n-m) { case (0, 0): // can reach here case (i, j): // can also reach here case (0, m): // illegal - cannot reach here } Pattern matching can be quite useful, even Scala has some of it, but when it's so limited its usefulness is limited too. Bye, bearophile
Nov 05 2008