Skip to content

const — examples

← all topics · 22 examples · page 1 of 1 · raw source ↓

Runs `test` → 19

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Body_Const_Folded_Arithmetic   topic: const   status: verified
// verified behavior: Test.test(...) == 19

namespace Test

func test() -> int {
    const A = 3
    const B = 4
    return A * B + A + B
}

Runs `test` → 12

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Body_Const_In_For_Range_Start   topic: const   status: verified
// verified behavior: Test.test(...) == 12

namespace Test

func test() -> int {
    const FROM = 3
    var sum = 0
    for i in FROM..6 {
        sum = sum + i
    }
    return sum
}

Runs `test` → 70

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Body_Const_In_Return_Expression   topic: const   status: verified
// verified behavior: Test.test(...) == 70

namespace Test

func test(n: int) -> int {
    const SCALE = 10
    return n * SCALE
}

Runs `test` → 21

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Body_Const_Passed_As_Arg   topic: const   status: verified
// verified behavior: Test.test(...) == 21

namespace Test

func triple(x: int) -> int = x * 3

func test() -> int {
    const N = 7
    return triple(N)
}

Runs `test` → 101

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Body_Const_Shadowed_In_Inner_Scope   topic: const   status: verified
// verified behavior: Test.test(...) == 101

namespace Test

func test() -> int {
    const X = 1
    var outer = X
    if true {
        const X = 100
        outer = outer + X
    }
    return outer
}

Runs `test` → 42

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Body_Const_Used_Locally   topic: const   status: verified
// verified behavior: Test.test(...) == 42

namespace Test

func test() -> int {
    const X = 21
    return X * 2
}

Runs `test` → 7

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Pub_Toplevel_Const_Emits_Public_Literal_Field   topic: const   status: verified
// verified behavior: Test.test(...) == 7

namespace Test

pub const VERSION = 7

func test() -> int = VERSION

Runs `test` → 50

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Static_Func_Const_Block_Member   topic: const   status: verified
// verified behavior: Test.test(...) == 50

namespace Test

static func Caps {
    const MAX_USERS = 50
    func limit() -> int = MAX_USERS
}

func test() -> int = Caps.limit()

Runs `test` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Toplevel_Const_Bool   topic: const   status: verified
// verified behavior: Test.test(...) == true

namespace Test

const ENABLED = true

func test() -> bool = ENABLED

Runs `test` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Toplevel_Const_Bool_Expression   topic: const   status: verified
// verified behavior: Test.test(...) == true

namespace Test

const ON = true
const OFF = false

func test() -> bool = ON and not OFF

Runs `test` → 3.14

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Toplevel_Const_Double   topic: const   status: verified
// verified behavior: Test.test(...) == 3.14

namespace Test

const PI = 3.14

func test() -> double = PI

Runs `test` → 60

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Toplevel_Const_Folded_Arithmetic   topic: const   status: verified
// verified behavior: Test.test(...) == 60

namespace Test

const SUM = 10 + 20 + 30

func test() -> int = SUM

Runs `test` → 105

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Toplevel_Const_In_Arithmetic   topic: const   status: verified
// verified behavior: Test.test(...) == 105

namespace Test

const BASE = 100

func test(x: int) -> int = BASE + x

Runs `is_big` → false

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Toplevel_Const_In_Comparison   topic: const   status: verified
// verified behavior: Test.is_big(...) == false

namespace Test

const THRESHOLD = 100

func is_big(n: int) -> bool = n > THRESHOLD

Runs `test` → 10

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Toplevel_Const_In_Loop_Bound   topic: const   status: verified
// verified behavior: Test.test(...) == 10

namespace Test

const COUNT = 5

func test() -> int {
    var total = 0
    for i in 0..COUNT {
        total = total + i
    }
    return total
}

Runs `test` → 1024

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Toplevel_Const_Int_Used_In_Func   topic: const   status: verified
// verified behavior: Test.test(...) == 1024

namespace Test

const MAX = 1024

func test() -> int = MAX

Runs `test` → -7

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Toplevel_Const_Negative   topic: const   status: verified
// verified behavior: Test.test(...) == -7

namespace Test

const NEG = -7

func test() -> int = NEG

Runs `test` → 10

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Toplevel_Const_References_Another_Const   topic: const   status: verified
// verified behavior: Test.test(...) == 10

namespace Test

const A = 5
const B = A * 2

func test() -> int = B

Runs `test` → "hello"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Toplevel_Const_String   topic: const   status: verified
// verified behavior: Test.test(...) == "hello"

namespace Test

const GREETING = "hello"

func test() -> string = GREETING

Runs `test` → "hello, world"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Toplevel_Const_String_Concat_Folded   topic: const   status: verified
// verified behavior: Test.test(...) == "hello, world"

namespace Test

const PREFIX = "hello, "
const NAME = "world"
const GREETING = PREFIX + NAME

func test() -> string = GREETING

Runs `test` → 42

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Toplevel_Const_With_Type_Annotation   topic: const   status: verified
// verified behavior: Test.test(...) == 42

namespace Test

const N: int = 42

func test() -> int = N

Runs `test` → 3

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::RefData_Const_Member   topic: const   status: unverified
// verified behavior: Test.test(...) == 3

namespace Test

ref data Config {
    const VERSION = 3
    init() {}
    func version() -> int = self.VERSION
}

func test() -> int {
    let c = Config()
    return c.version()
}