const — examples
← all topics · 28 examples · page 1 of 1 · raw source ↓
Runs `go` → "hi"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ForwardConstructionTests.cs::ExternalCtor_OptionalTail_Filled topic: const status: verified
// verified behavior: Test.go(...) == "hi"
namespace Test
func go() -> string {
let ms = MemoryStream()
let w = StreamWriter(ms)
w.Write("hi")
w.Flush()
return Encoding.UTF8.GetString(ms.ToArray())
}Runs `go` → 7
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ForwardConstructionTests.cs::FieldDefault_Constructs_LaterDeclaredType topic: const status: verified
// verified behavior: Test.go(...) == 7
namespace Test
pub class Holder {
box: Box = Box(7)
init(unused: int) { }
pub func read() -> int = self.box.v
}
pub class Box {
v: int
init(v: int) { self.v = v }
}
func go() -> int {
let h = Holder(0)
return h.read()
}Runs `go` → 1
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ForwardConstructionTests.cs::Init_Constructs_LaterDeclaredType_SameFile topic: const status: verified
// verified behavior: Test.go(...) == 1
namespace Test
pub class Host {
carrier: Carrier
init(seed: int) {
self.carrier = Carrier(seed)
}
pub func ping() -> int = self.carrier.ping()
}
pub class Carrier {
seed: int
init(seed: int) {
self.seed = seed
}
pub func ping() -> int = self.seed
}
func go() -> int {
let h = Host(1)
return h.ping()
}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 = VERSIONRuns `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 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 = ENABLEDRuns `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 OFFRuns `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 = PIRuns `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 = SUMRuns `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 + xRuns `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 > THRESHOLDRuns `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 = MAXRuns `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 = NEGRuns `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 = BRuns `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 = GREETINGRuns `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 = GREETINGRuns `null` → "hello"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Toplevel_Const_Used_In_RefData_InstanceMethod topic: const status: verified
// verified behavior: Test.null(...) == "hello"
namespace Test
const GREETING = "hello"
pub class Box {
pub func get() -> 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 = NRuns `null` → 42
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ForwardConstructionTests.cs::Init_Constructs_TypeFromLaterFile topic: const status: unverified
// verified behavior: Test.null(...) == 42
namespace Test
pub class Host {
carrier: Carrier
init(seed: int) {
self.carrier = Carrier(seed)
}
pub func ping() -> int = self.carrier.ping()
}
pub func go() -> int {
let h = Host(41)
return h.ping() + 1
}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
class Config {
const VERSION = 3
init() {}
func version() -> int = self.VERSION
}
func test() -> int {
let c = Config()
return c.version()
}Runs `bump` → 107
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Const.cs::Toplevel_LetAndVar_AreModuleState topic: const status: unverified
// verified behavior: Test.bump(...) == 107
Namespace-scope `let`/`var` (Go-style package state) not yet parsed — only `const` is accepted at namespace scope today (ES0001 on `let`/`var`).