Cobra Release 0.7.3
Cobra 0.7.3 adds How To examples for contracts, threads and forms programming. Additionally, there are ten refinements and thirteen bugfixes to the language and libraries.
How To's
There are new How To's for:
Refinements
Language Refinements
- Added underscore as a line continuation character (_). This can be used for any line at all. The next line has to have the same level of indentation or greater.
def method(a as int, _
b as int)
print a, b
Also, the continued line is the one place you can mix tabs and spaces for indentation by using spaces after the tabs to line up your continuation line with the one above to suit your taste. If you're using spaces for indentation, you can use as many or as few extra spaces for alignment.
- Added new syntax for including C# code which is to prefix a string literal with the word "sharp" and no space between. This fits in with other prefixes such as "r" for raw strings, "ns" for no substitution and "c" for characters. The string literal can use single or double quotes. It is treated as a raw string so there is no substitution/interpolation or interpretation of escape codes.
print sharp'new Object().GetHashCode()'
print sharp"new Object().GetHashCode()"
- Improved the message for overriding contracts with or require and and ensure.
error: The contract must be declared "or require" rather than "require" because the code member is "override".
- Improved the error message for a return statement that returns a value in a method not declared to return anything (eliminated reference to "void" which never shows up in Cobra source).
- There is a new ct_trace statement that prints compile-time information about an expression. This is primarily useful if you are developing on the Cobra compiler, although you might use it see what type has been inferred by the compiler. There is no effect at run-time.
for entry in someDictionary
ct_trace entry
- Improved naming conventions when reading DLLs. For example, you now write Math.pi instead of Math.pI and Environment.osVersion instead of Environment.oSVersion.
Other Refinements
- Added new -optimize (or -o for short) flag to enable optimizations in the C# backend.
cobra -c -o myprog.cobra
- Cobra now gives suggestions for unknown member names.
foo.cobra(4): error: Cannot find a definition for "OSVersion" in "Environment". There are members with similar names including "osVersion", "getOSVersionString" and "version".
- Characters now have properties which are mapped to the .NET Char struct static/shared method calls:
c.getNumericValue
c.getUnicodeCategory
c.isControl
c.isDigit
c.isHighSurrogate
c.isLetter
c.isLetterOrDigit
c.isLower
c.isLowSurrogate
c.isNumber
c.isPunctuation
c.isSeparator
c.isSurrogate
c.isSymbol
c.isUpper
c.isWhiteSpace
c.toLower
c.toLowerInvariant
c.toUpper
c.toUpperInvariant
c.toString
- Added SomeType.getType to return the System.Type that implements SomeType at run-time. (C# users know this as typeof(SomeType).)
print System.String.getType
Fixes
- Fixed: Cannot 'ref' an overloaded method even when the context (such as listen obj.someEvent) disambiguates the choices.
- Fixed: Cannot successfully run cobra.exe on Novell Mono on MS Windows
- Fixed: Properties using the shortcut syntax from var don't invoke the invariant.
- Fixed: Code in invariant expressions can reinvoke the invariant leading to infinite recursion.
- Fixed: An invariant condition that is not an explicit boolean expression (such as name.length) causes invalid code generation.
- Fixed: Cannot instantiate a qualified type name with only one namespace (A.B() fails, A.B.C() works).
- Fixed: The compiler does not correctly recognize that a struct inherits/implements an interface.
- Fixed: Referencing method names in a DLL that start with lowercase letters (which is not the norm) does not work.
- Fixed: Nested classes in DLLs are not read. This also means that .controls cannot be referenced in a subclass of Form in WinForms.
- Fixed: A method with a return type and a single throw statement generates a false error message ("Missing return...").
- Fixed: Assigning a method or property that returns a System enum to a local variable causes bad code generation.
- Fixed: Cannot put a comment above a file-level doc string (false compile error).
- Fixed: Cannot use spaces for indenting doc strings.