hi
Posted: Wed Oct 06, 2010 9:39 pm
Hi all,
I am a newbie to cobra and am having some problem in understanding some of the stuff here.
In the introductory codes that are provided like class Fib where Fibonacci series is calculated till tenth term. The loop is as follows
for i in n
n has been initialised to 10 but i is declared first time and not even initialised! I have had experience with python but then too the code looks something like this for i in range(n). Although I have seen dynamic typing but I feel kind of extreme.
How does i iterate over n ? I mean first of all how does i initialise to zero and then the loop looks like a typical "for each" rather than for loop so what type is 'i' ? Is it a iterator ? I mean is n cast to some sort of enumerable thing and the compiler makes a list of it and then you iterate over that range or something else.
I am sorry if I am bugging everyone else by over thinking or complicating this stuff but I am curious to know what is happening behind the hood.
Some of my view points
Does forcing the opening brace "(" right after method definition name have any advantage ? I program in some other langauges where I use space liberally that is method name space opening and closing parentheses. Just a minor issue but felt sort of awkward. Similar for the case when specifying the List<T> generic thing this being not valid List< T > (notice the space between arguments and bracket) unlike Java or C#. Funny thing is cobra allows me to put space between parentheses and argument names in between them.
No incremence or decremence operator. I do not get it completly but is there any advantage in throwing out ++ and -- operators.
What does keyword is shared means and are methods in cobra static as like in Java since in the program the method is called as Fib.compute() that is class name and dot operator method name. Or is it some sort of access modifier like public, private, protected.
Lastly the following code refused to run on my machine though I copied it word to word from site
class Fib inherits List<of int>
def init( count as int )
base.init( count )
a, b = 0, 1
for i in count
.add(b)
save = a
a = b
b += save
class Program
def main is shared
i = 1
for n in Fib.( 10 )
print '[i]. [ n ]'
i += 1
It just said
error: COBRA INTERNAL ERROR / InvalidCastException / Cannot cast from source type to destination type.
Compilation failed - 1 error, 0 warnings
regards,
Soham
I am a newbie to cobra and am having some problem in understanding some of the stuff here.
In the introductory codes that are provided like class Fib where Fibonacci series is calculated till tenth term. The loop is as follows
for i in n
n has been initialised to 10 but i is declared first time and not even initialised! I have had experience with python but then too the code looks something like this for i in range(n). Although I have seen dynamic typing but I feel kind of extreme.
How does i iterate over n ? I mean first of all how does i initialise to zero and then the loop looks like a typical "for each" rather than for loop so what type is 'i' ? Is it a iterator ? I mean is n cast to some sort of enumerable thing and the compiler makes a list of it and then you iterate over that range or something else.
I am sorry if I am bugging everyone else by over thinking or complicating this stuff but I am curious to know what is happening behind the hood.
Some of my view points
Does forcing the opening brace "(" right after method definition name have any advantage ? I program in some other langauges where I use space liberally that is method name space opening and closing parentheses. Just a minor issue but felt sort of awkward. Similar for the case when specifying the List<T> generic thing this being not valid List< T > (notice the space between arguments and bracket) unlike Java or C#. Funny thing is cobra allows me to put space between parentheses and argument names in between them.
No incremence or decremence operator. I do not get it completly but is there any advantage in throwing out ++ and -- operators.
What does keyword is shared means and are methods in cobra static as like in Java since in the program the method is called as Fib.compute() that is class name and dot operator method name. Or is it some sort of access modifier like public, private, protected.
Lastly the following code refused to run on my machine though I copied it word to word from site
class Fib inherits List<of int>
def init( count as int )
base.init( count )
a, b = 0, 1
for i in count
.add(b)
save = a
a = b
b += save
class Program
def main is shared
i = 1
for n in Fib.( 10 )
print '[i]. [ n ]'
i += 1
It just said
error: COBRA INTERNAL ERROR / InvalidCastException / Cannot cast from source type to destination type.
Compilation failed - 1 error, 0 warnings
regards,
Soham