Release Notes

Cobra Release 0.7.1

Cobra 0.7.1 adds struct declarations, improves run-time performance, makes minor refinements and fixes a handful of bugs.

Language Improvements

Structs

Cobra supports structs now:

struct Point test p = Point(3, 4) assert p.x == 3 assert p.y == 4 assert p.toString == 'Point(3, 4)' var _x as int var _y as int def init(x as int, y as int) _x = x _y = y get x from var get y from var def toString as String is override return 'Point([.x], [.y])'

For Expressions

Cobra allows for x in y where x > 0 ... in other words, you can skip the final get x in the presence of where ....

n = [1, -1, 3, -7, 5] assert (for x in n where x > 0) == [1, 3, 5]

Of course, you'll still use get when transforming the value:

n = [1, -1, 3, -7, 5] assert (for x in n where x > 0 get x*x) == [1, 9, 25]

Minor

Added any as a reserved word in anticipation of an any <sequence> operator that returns true if any element in the sequence is true. The word all, which could be used in a similar fashion (but returning true if all elements are true), was already reserved.

Miscellaneous

Contract Code Generation

Recall that Cobra supports contracts like so:

class Factory def makeWidget(name as String, priority as int) as IWidget require name.trim <> '' priority > 0 ensure result.factory is this result.name == name.trim result.priority == priority body ...

Now there is a new "-contracts:..." command line option with choices: none, inline or methods. The "inline" choice is the default which results in a performance boost over the previous version of Cobra. A call to an empty method is up to 150 times faster than before. More realistic effects on actual applications range from 0% to 20%.

The "methods" options may be useful when splitting projects across libraries.

Here is an example from the command line:

cobra -contracts:none myprog.cobra

Pex

I met Peli de Halleux of the Pex project at the Lang.NET 2008 Symposium where he demonstrated the ability of Pex to automatically find errors in code! We put a Cobra sample through it and bugs in the methods that were due to weaknesses in the contracts. It turns out that Pex can work with preconditions which are a built-in feature in Cobra.

Let's hope Pex is available for general consumption soon.

Library

There are some new properties and methods in CobraCore. The most notable is runCobraExe which makes invoking "cobra.exe" from your own programs easy.

class CobraCore shared get versionDescription as String """ Returns a textual description of the version such as "X.Y.Z" or "svn-post-X.Y.Z". """ get isOfficialRelease as bool def runCobraExe(args as String, process as out System.Diagnostics.Process?) as String """ Runs cobra.exe with the given args, sets the process to the one created for cobra.exe and returns all output including stdio and stderr. In addition to examining the output, you should be interested in process.exitCode which will be zero if there was no problems. Uses CobraCore.findCobraExe and raises IOException if it cannot be found. """ def runCobraExe(cobraExePath as String, args as String, process as out System.Diagnostics.Process?) as String def reset(printDestination as TextWriter) """ Resets the Cobra run-time support using the argument as the initial print destination on the "print to" stack. This is occasionally needed in special circumstances such as running with Pex (http://research.microsoft.com/pex/). """ def reset

Fixes