From what I can see, Cobra seems to "rename" all .NET methods to start in lowercase, i.e. Console.WriteLine because Console.writeLine etc. Does that apply to any .NET assembly, for example if I created a C# type with PascalCase methods, do I have to call them as camelCase in Cobra?
Also a quick question about print. In Python 2, adding a comma after a print statement removed the newline. In Cobra, adding a comma is legal, but it doesn't seem to do anything. What am I missing here?
Forums
New names for .NET types?
4 posts
• Page 1 of 1
Re: New names for .NET types?
Only methods and properties start lower case. Type names (which include classes, interfaces, structs and delegates) remain uppercase.
Typically if you get the case incorrect, the Cobra compiler will directly tell you the correct case right in the error message.
You can also experiment with "cobra -correct-source ..." which will autocorrect some of these for you by writing back to your source code. If you can configure your editor to automatically reload modified files, this can save you some time. But it's also the feature everyone is afraid of.
Cobra uses the keyword "stop" as in:
Unlike with a comma, there is no additional space printed. There is additional information at the Print Statement wiki page.
Typically if you get the case incorrect, the Cobra compiler will directly tell you the correct case right in the error message.
You can also experiment with "cobra -correct-source ..." which will autocorrect some of these for you by writing back to your source code. If you can configure your editor to automatically reload modified files, this can save you some time. But it's also the feature everyone is afraid of.
Cobra uses the keyword "stop" as in:
print 'Prompt:' stop
Unlike with a comma, there is no additional space printed. There is additional information at the Print Statement wiki page.
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: New names for .NET types?
Thanks again. I have another question. Here's my code:
So my question is, why does the last line fail? I figured the expression "myList[i]" evaluates to a type, so I should be allowed to add a pair of parentheses after just like I can with the variable "type" in the previous line.
Also, in that example, is blah() resolved statically or dynamically? In C# I would have had to say type is a dynamic but I'm not sure how Cobra does it.
class A
def blah
print "A!"
class B
def blah
print "B!"
class C
def blah
print "C!"
class Program
def main
myList = [A, B, C]
for i, type in myList.numbered
# This works:
type = myList[i]
type().blah
# This fails with 6 errors about brackets and parentheses
myList[i]().blah
So my question is, why does the last line fail? I figured the expression "myList[i]" evaluates to a type, so I should be allowed to add a pair of parentheses after just like I can with the variable "type" in the previous line.
Also, in that example, is blah() resolved statically or dynamically? In C# I would have had to say type is a dynamic but I'm not sure how Cobra does it.
- Dr_Asik
- Posts: 7
Re: New names for .NET types?
When you have a reference to a System.Type, as you do in your example, you can instantiate it with parens, as you have done. Cobra considers the type to be "dynamic" since there is no other reasonable choice (other than System.Object, but that's not as useful).
If you know more about the type of what you're instantiating, you can use a type cast like:
But you don't have to do that. Cobra supports both dynamic and static typing.
The last line in your example has triggered a bug in the code generation for which I'll add a ticket. The workaround is reasonable--break up the expression like you did above.
If you know more about the type of what you're instantiating, you can use a type cast like:
obj = type() to Shape
But you don't have to do that. Cobra supports both dynamic and static typing.
The last line in your example has triggered a bug in the code generation for which I'll add a ticket. The workaround is reasonable--break up the expression like you did above.
- Charles
- Posts: 2515
- Location: Los Angeles, CA
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 4 guests