Using Cobra from the lastest source code
Posted: Thu Sep 18, 2008 10:48 am
It's been awhile since the last release of Cobra, but not due to lack of progress. I've often been obsessing over getting another refinement or bugfix in for the next release. In this post, I'd like to point out that it's very easy to use Cobra out of the source code repository. Upon doing so, you'll get the additional features and fixes described below. Plus you can provide feedback for the upcoming release. The repository is usually quite stable due to the automated regression test suite.
See http://cobra-language.com/source/
Building Cobra is very easy. See the instructions in cobra-workspace\Developer\ImplementationNotes.text
Here I have pasted in the IntermediateReleaseNotes.text file found in the Developer directory:
* Added support for "extended initializers" which allow you to set properties of the object in the same call being used to create the object:
* Added partial classes, a la C# and VB. This enables class (and struct) declarations to be split across files. This can be useful for organizing generated code or even manually written code based on purpose. ticket:10
* Added new comment markers /# ... #/ which can be used for block comments and inline comments. Block comments must start at the beginning of a line and can be used to comment out multiple lines of source. They can be nested. Inline comments also start with /# and end with #/, but within the same line. They can be used to comment out a portion of a line. Regular end of line comments are still available and still the norm.
* Added support for warning suppression on arbitrary lines by placing a trailing comment containing `.no-warnings.` after the `#`
.code
this.call() # .no-warnings.
* Added support for a Cobra compiler directive to specify the type for `number`
type of number and integer literals same as command line -number option
%% number 'decimal' | 'float' | 'float32' | 'float64'
* Added support for implicit line continuation for items in parentheses.
i.e method call argument lists, method declaration parameters and
parenthesised expressions.
* Added a new built-in doc tool accessible via "cobra -doc ...". The documentation is generated to local HTML files using your declarations, doc strings, contracts, etc.
* Added support for declaring and raising events. When raising events, passing "this" is implied (e.g., not required) since that is the normal behavior for events. Also, if the events argument has a default constructor, it too can be omitted.
* Add support for specifying unsigned integers as Hex literals
e.g. 0x7f 0x7f_8 0x7Fu16 0x7F_u32
* The default type for vars, properties and method arguments is now `dynamic?`. Also the result type for `d.foo` where `d` is dynamic is now `dynamic?` instead of `dynamic`. These changes reflect the flexibility that was originally intended with default types and dynamic typing.
* Added new `all` and `any` unary operators that take something enumerable (such as a list, set or generator) and return a boolean (true or false) indicating if all or any of the elements are true. These operators increase expressiveness in conditions. For example, a contract might use these operators:
.code
def foo(items as IList<of Item>)
require all for item in items get item.name.trim.length > 0
* Added generic methods.
* Added new Visitor class to the Cobra standard library. Subclasses can easily implement the visitor pattern and the classes being visited require no additional modification. See the doc string of `Visitor` in CobraLang.cobra for details.
* Added support for attributes on class/object variables (also know as "fields").
* Cobra now prints '[1, 2, 3]' for a list of integers rather than 'System.Collections.Generic.List`1[System.Int32]'. It still uses the standard List<of> class.
Added new Cobra library classes StringMaker (abstract), PrintStringMaker and TechStringMaker and associated properties CobraCore.printStringMaker and CobraCore.techStringMaker. Through those properties, you can customize the output of `print` statements and string substitution (.printStringMaker), and assert failures and `trace` statements (.techStringMaker).
For convenience, the extension methods .toPrintString and .toTechString have been added to System.Object.
* You can now say `get foo from var is override`. In other words, you can add "is names" after a "from var" property declaration.
* The backend C# compiler is now invoked via .NET's CSharpCodeProvider (also tested on Mono). This eliminates problems with locating the installed C# compiler and speeds up the regression tests. You can still use the -sharp-compiler option to dictate the backend C# compiler if you desire.
* The Cobra run-time will no longer throw IndexOutOfRangeException for slicing. At worst, you will get an empty list. This is more convenient and matches Python's semantics. Thanks to "hopscc" in New Zealand.
* There are three places where non-nil is verified at run-time: class variables at the end of an initializer, arguments at the beginning of a method and "to !" casts. Added new -include-nil-checks:yes|no option which includes or excludes these checks. Default is 'yes'. Using -turbo will set to 'no'.
* Renamed CobraCore.willCheckNonNilClassVars to CobraCore.willCheckNil
* Integer literals can now be suffixed to indicate their type such as `1_u64` and `7_i8`. The underscore is optional and valid sizes include 8, 16, 32 and 64. There is no reason to ever suffix zero (0). Credit: hopscc
* In string literals, square brackets can be escaped with a backslash to prevent expression substitution. ticket:15
* A single underscore marks a class member as `protected` (or a struct member as `private`). Previously, this behavior only took place for variables, but now takes place for all types of members including properties and methods. Also, two underscores now implies `private`.
* (minor) Fix BinaryOp.writeSharpBreakdownItems to indent and outdent around its subexpressions.
* Added keyword `each`, reserved for future use. Removed keywords `down`, `global`, `instance` and `step`.
* Fixed: The Cobra command line compiler throws an exception for files with an all capital extension (FOO.COBRA).
* Fixed: Using "continue" in new style numeric for loops does not increment the loop variable. ticket:9
* Fixed: Cannot access classes that start with a lower case letter such as iDB2Connection. ticket:16
* Fixed: Looping through an object that inherits IEnumerator<of T>, but with T that has constraints, does not recognize those constraints in the body of the `for` loop. For example, if T is constrained to be an ICar, the .drive method cannot be invoked.
* Fixed: Cannot assign or compare qualified types such as `System.Object` even though the same can be done with unqualified types such as `Object`.
* Fixed: Cannot implement a method whose signature is matched by an extension method of a base class.
* Fixed: Method return types from generics in DLLs are always considered nilable even if the generic parameter was not (such as `bool`). ticket:22
* Fixed: Assignments (and other side effects) can appear in assert conditions even though they might be excluded during compilation or run-time. ticket:4 (hopscc)
* Fixed: Cannot use the `branch` statement if the expression has a dynamic type.
* Fixed: Using `ref` on a variable that experienced an error causes an internal exception.
* Fixed: Some bitwise operations with integer literals of 16 or 8 bits produce invalid compilation errors.
* Fixed: Putting a comment after a doc string, but before a `test` section causes an invalid compilation error.
See http://cobra-language.com/source/
Building Cobra is very easy. See the instructions in cobra-workspace\Developer\ImplementationNotes.text
Here I have pasted in the IntermediateReleaseNotes.text file found in the Developer directory:
* Added support for "extended initializers" which allow you to set properties of the object in the same call being used to create the object:
r = Rectangle(p1=Point(x=0, y=1), p2=Point(x=2, y=3))
c = Customer('Acme, Inc.', region=Regions.South)
* Added partial classes, a la C# and VB. This enables class (and struct) declarations to be split across files. This can be useful for organizing generated code or even manually written code based on purpose. ticket:10
# file Foo.cobra
class Foo
is partial
var _name as String
pro name from var
# file Foo.gen.cobra
class Foo
is partial
def generatedMethod
pass
* Added new comment markers /# ... #/ which can be used for block comments and inline comments. Block comments must start at the beginning of a line and can be used to comment out multiple lines of source. They can be nested. Inline comments also start with /# and end with #/, but within the same line. They can be used to comment out a portion of a line. Regular end of line comments are still available and still the norm.
class Example
def main is shared
# an end-of-line comment
t = [1, 2, 3] # a list of numbers
# an inline comment
print t, /#t[0],#/ t.count
# a block comment
/#
def foo
print 'bar'
#/
* Added support for warning suppression on arbitrary lines by placing a trailing comment containing `.no-warnings.` after the `#`
.code
this.call() # .no-warnings.
* Added support for a Cobra compiler directive to specify the type for `number`
type of number and integer literals same as command line -number option
%% number 'decimal' | 'float' | 'float32' | 'float64'
* Added support for implicit line continuation for items in parentheses.
i.e method call argument lists, method declaration parameters and
parenthesised expressions.
* Added a new built-in doc tool accessible via "cobra -doc ...". The documentation is generated to local HTML files using your declarations, doc strings, contracts, etc.
* Added support for declaring and raising events. When raising events, passing "this" is implied (e.g., not required) since that is the normal behavior for events. Also, if the events argument has a default constructor, it too can be omitted.
* Add support for specifying unsigned integers as Hex literals
e.g. 0x7f 0x7f_8 0x7Fu16 0x7F_u32
* The default type for vars, properties and method arguments is now `dynamic?`. Also the result type for `d.foo` where `d` is dynamic is now `dynamic?` instead of `dynamic`. These changes reflect the flexibility that was originally intended with default types and dynamic typing.
* Added new `all` and `any` unary operators that take something enumerable (such as a list, set or generator) and return a boolean (true or false) indicating if all or any of the elements are true. These operators increase expressiveness in conditions. For example, a contract might use these operators:
.code
def foo(items as IList<of Item>)
require all for item in items get item.name.trim.length > 0
* Added generic methods.
* Added new Visitor class to the Cobra standard library. Subclasses can easily implement the visitor pattern and the classes being visited require no additional modification. See the doc string of `Visitor` in CobraLang.cobra for details.
* Added support for attributes on class/object variables (also know as "fields").
* Cobra now prints '[1, 2, 3]' for a list of integers rather than 'System.Collections.Generic.List`1[System.Int32]'. It still uses the standard List<of> class.
Added new Cobra library classes StringMaker (abstract), PrintStringMaker and TechStringMaker and associated properties CobraCore.printStringMaker and CobraCore.techStringMaker. Through those properties, you can customize the output of `print` statements and string substitution (.printStringMaker), and assert failures and `trace` statements (.techStringMaker).
For convenience, the extension methods .toPrintString and .toTechString have been added to System.Object.
* You can now say `get foo from var is override`. In other words, you can add "is names" after a "from var" property declaration.
* The backend C# compiler is now invoked via .NET's CSharpCodeProvider (also tested on Mono). This eliminates problems with locating the installed C# compiler and speeds up the regression tests. You can still use the -sharp-compiler option to dictate the backend C# compiler if you desire.
* The Cobra run-time will no longer throw IndexOutOfRangeException for slicing. At worst, you will get an empty list. This is more convenient and matches Python's semantics. Thanks to "hopscc" in New Zealand.
* There are three places where non-nil is verified at run-time: class variables at the end of an initializer, arguments at the beginning of a method and "to !" casts. Added new -include-nil-checks:yes|no option which includes or excludes these checks. Default is 'yes'. Using -turbo will set to 'no'.
* Renamed CobraCore.willCheckNonNilClassVars to CobraCore.willCheckNil
* Integer literals can now be suffixed to indicate their type such as `1_u64` and `7_i8`. The underscore is optional and valid sizes include 8, 16, 32 and 64. There is no reason to ever suffix zero (0). Credit: hopscc
* In string literals, square brackets can be escaped with a backslash to prevent expression substitution. ticket:15
* A single underscore marks a class member as `protected` (or a struct member as `private`). Previously, this behavior only took place for variables, but now takes place for all types of members including properties and methods. Also, two underscores now implies `private`.
* (minor) Fix BinaryOp.writeSharpBreakdownItems to indent and outdent around its subexpressions.
* Added keyword `each`, reserved for future use. Removed keywords `down`, `global`, `instance` and `step`.
* Fixed: The Cobra command line compiler throws an exception for files with an all capital extension (FOO.COBRA).
* Fixed: Using "continue" in new style numeric for loops does not increment the loop variable. ticket:9
* Fixed: Cannot access classes that start with a lower case letter such as iDB2Connection. ticket:16
* Fixed: Looping through an object that inherits IEnumerator<of T>, but with T that has constraints, does not recognize those constraints in the body of the `for` loop. For example, if T is constrained to be an ICar, the .drive method cannot be invoked.
* Fixed: Cannot assign or compare qualified types such as `System.Object` even though the same can be done with unqualified types such as `Object`.
* Fixed: Cannot implement a method whose signature is matched by an extension method of a base class.
* Fixed: Method return types from generics in DLLs are always considered nilable even if the generic parameter was not (such as `bool`). ticket:22
* Fixed: Assignments (and other side effects) can appear in assert conditions even though they might be excluded during compilation or run-time. ticket:4 (hopscc)
* Fixed: Cannot use the `branch` statement if the expression has a dynamic type.
* Fixed: Using `ref` on a variable that experienced an error causes an internal exception.
* Fixed: Some bitwise operations with integer literals of 16 or 8 bits produce invalid compilation errors.
* Fixed: Putting a comment after a doc string, but before a `test` section causes an invalid compilation error.