Page 1 of 1

Cobra November 2008 Update

PostPosted: Sun Nov 30, 2008 6:31 pm
by Charles
This is a new update for November, covering improvements since the last update in October.

There is a new HowToInstallFromSource wiki page covering the ease and benefits of using Cobra from the source repository, and how to do it.

The following improvements are due to patches and feedback from the community as well as my own efforts. Thanks to all contributors!


-- Added anonymous methods, also known as closures. Discussed here.

-- Added streams to the language. Discussed here.

-- Added generic constraints on generic methods. See Tests/240-generics/400-generic-methods/130-generic-method-constraints.cobra

-- Added a shortcut syntax for declaring a property and its backing variable in one line.
class X

get x from var as int
# is a short cut for these two lines:
var _x as int
get x from var

# the general form of the shortcut above is:
get <name> from var as <type>

# the fully general form is:
(get|pro|set) <name> from (var|<var-name>) as <type>

-- Added storage type specification for enums. "enum State of uint8"

-- Add support for multitarget assignment in for statements:
for key, value in aDictionary
trace key, value
for a, b in [[1, 2], [3, 4]]
print a + b

-- Added support for one-line doc strings.
class X

def foo
""" Foo is as foo does. """

Command Line

-- Added command line option -correct-case (or -cc) to change the case of types to the correct cases in situations that are not ambiguous. For example, "list<of int>" will be rewritten as "List<of int>" rather than producing an error. If you can configure your editor to automatically reload modified files then this feature can be quite nice.

-- Added "-out:" command line option to control the name of the resulting executable or library.

-- Support file paths with both backslash (foo\bar.cobra) and forward slash (foo/bar.cobra) regardless of platform.

-- Make the -files: option "relative" meaning that the paths inside that file are relative to that file (instead of say, the current working directory).

-- Updated -about with more URLs for license, support, etc.

-- The default behavior for invoking the Cobra command line with no args is now -about rather than -help.

-- Better error messages regarding invalid option choices.


-- Made various improvements to "install-from-workspace" based on user feedback and patches.

-- Added new Point sample.

-- Added new "line endings" program which is useful if you work on Mac, Windows and Windows+cygwin. Look under cobra-workspace/Supplements/le.cobra.

-- Updated and added various wiki pages.

-- Fixed 15 bugs.

-- Improved 5 error messages.

The next update will be next month, towards the end of December, but you can always keep up to date by browsing through the discussion forums.

I hope you'll try out the very latest Cobra!

Best regards,


Re: Cobra November 2008 Update

PostPosted: Mon Dec 01, 2008 4:22 am
by helium

Re: Cobra November 2008 Update

PostPosted: Tue Dec 02, 2008 1:33 pm
by relez
Great! This is almost a 0.9 verson....

Re: Cobra November 2008 Update

PostPosted: Sun Dec 07, 2008 10:12 pm
by gauthier
the generic constraint test seems bogus: it doesn't call or assert over swapIfGreater method

Also I would like to know how to constraint for new() and declare multiple constraints (for multiple type parameters, and multiple constraints over a single type parameter)


Re: Cobra November 2008 Update

PostPosted: Mon Dec 08, 2008 12:01 am
by Charles
You're right the test case does not invoke that method. Although it *does* compile, load and run with no complaints from C# or .NET. If the constraint did not exist in the generated code, then the .compareTo invocation would have choked the backend compilation since System.Object has no such method.

Use the keyword "callable" for types on which you want to create instances via calling:
T(i, j)

For multiple constraints, separate them with commas.

See also <workspace>\Tests\240-generics\300-declare-generic-classes\602-instantiate-generic-arg.cobra