const / readonly member
Posted: Sat Jan 03, 2009 8:41 pm
is there any way to define const members?
Discussion about the Cobra programming language.
http://cobra-language.com/forums/
class X
get two as int is shared
return 2
/ c# const_keyword_2.cs
using System;
public class MainClass
{
static void Main()
{
const int c = 707;
Console.WriteLine("My local constant = {0}", c);
}
}
class MainClass
def main is shared
c as int = 707 is const # new
assert c == 707
class Foo
final a = 3.0 is shared # eq. to "const" in C#
final b = 4 # eq. to "readonly" in C#
final c = "foo" is shared # eq. to "static readonly"
final b = "bar" # eq. to "readonly"
class Test
def main is shared
final i = 0 # eq. to "const"
final str = "foo" # eq. to "const"
i = 1 # error
str = "bar" # error
Foo.a = 4.0 # error
Foo.c = "" # error
f = Foo()
f.b = 3.0 # error
f.d = "" # error
class Foo
const pi = 3.14 is shared # class constant
const e = 2.718281828 # object constant
class Foo
final a = 3.0 is shared # eq. to "const" in C#, static final in java
final b = 4 # eq. to "readonly" in C#, final in java
foo = MyLib.MyClass.Limit
# then if Limit is a const, the compiler does this:
foo = 100
# if Limit is a readonly, the compiler does this:
foo = <value of Limit in MyLib.MyClass.Limit at load time>
val newLine = '\n'
val two = 2