core — examples
← all topics · 698 examples · page 7 of 14 · raw source ↓
Runs `go` → 123
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_Parse topic: core status: verified
// verified behavior: Test.go(...) == 123
namespace Test
func go() -> int { return int.Parse("123") }Runs `go` → 1024
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_PowerOfTwoChain topic: core status: verified
// verified behavior: Test.go(...) == 1024
namespace Test
func go() -> int {
var n = 1
for i in 0..10 {
n *= 2
}
return n
}Runs `go` → 14
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_PrecedenceMulOverAdd topic: core status: verified
// verified behavior: Test.go(...) == 14
namespace Test
func go() -> int { return 2 + 3 * 4 }Runs `go` → 54
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_Sub_Mul topic: core status: verified
// verified behavior: Test.go(...) == 54
namespace Test
func go() -> int {
let a = 10 - 4
return a * 9
}Runs `go` → 3
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_TruncatingDivision topic: core status: verified
// verified behavior: Test.go(...) == 3
namespace Test
func go() -> int { return 7 / 2 }Runs `go` → -3
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_TruncationTowardZero_Negative topic: core status: verified
// verified behavior: Test.go(...) == -3
namespace Test
func go() -> int { return -7 / 2 }Runs `go` → -1
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_TryParse_Failure topic: core status: verified
// verified behavior: Test.go(...) == -1
namespace Test
func go() -> int {
if int.TryParse("notnum", out var n) {
return n
}
return -1
}Runs `go` → 42
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_TryParse_Success topic: core status: verified
// verified behavior: Test.go(...) == 42
namespace Test
func go() -> int {
if int.TryParse("42", out var n) {
return n
}
return -1
}Runs `go` → -42
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_UnaryMinus topic: core status: verified
// verified behavior: Test.go(...) == -42
namespace Test
func go() -> int {
let x = 42
return 0 - x
}Runs `go` → 1_000_000
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_UnderscoreSeparators topic: core status: verified
// verified behavior: Test.go(...) == 1_000_000
namespace Test
func go() -> int { return 1_000_000 }Runs `add` → 7_000_000_000L
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Long_Add topic: core status: verified
// verified behavior: Test.add(...) == 7_000_000_000L
namespace Test
func add(a: long, b: long) -> long { return a + b }Runs `go` → long.MaxValue
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Long_MaxValueConstant topic: core status: verified
// verified behavior: Test.go(...) == long.MaxValue
namespace Test
func go() -> long { return long.MaxValue }Runs `mod` → 2L
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Long_Modulo topic: core status: verified
// verified behavior: Test.mod(...) == 2L
namespace Test
func mod(a: long, b: long) -> long { return a % b }Runs `mul` → 6_000_000_000L
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Long_Multiply topic: core status: verified
// verified behavior: Test.mul(...) == 6_000_000_000L
namespace Test
func mul(a: long, b: long) -> long { return a * b }Runs `go` → 9_000_000_000L
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Long_Parse topic: core status: verified
// verified behavior: Test.go(...) == 9_000_000_000L
namespace Test
func go() -> long { return long.Parse("9000000000") }Runs `sub` → 1_000_000_000L
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Long_Subtraction topic: core status: verified
// verified behavior: Test.sub(...) == 1_000_000_000L
namespace Test
func sub(a: long, b: long) -> long { return a - b }Runs `add` → (sbyte)1
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Sbyte_Arithmetic topic: core status: verified
// verified behavior: Test.add(...) == (sbyte)1
namespace Test
func add(a: sbyte, b: sbyte) -> sbyte { return a + b }Runs `echo` → (sbyte)-5
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Sbyte_Negative topic: core status: verified
// verified behavior: Test.echo(...) == (sbyte)-5
namespace Test
func echo(b: sbyte) -> sbyte { return b }Runs `add` → (short)7
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Short_Add topic: core status: verified
// verified behavior: Test.add(...) == (short)7
namespace Test
func add(a: short, b: short) -> short { return a + b }Runs `sub` → (short)100
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Short_Subtraction topic: core status: verified
// verified behavior: Test.sub(...) == (short)100
namespace Test
func sub(a: short, b: short) -> short { return a - b }Runs `go` → false
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::ShortCircuit_And_DoesNotEvaluateRight topic: core status: verified
// verified behavior: Test.go(...) == false
namespace Test
func go() -> bool {
let d = 0
return d != 0 && (10 / d) > 0
}Runs `go` → true
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::ShortCircuit_Or_DoesNotEvaluateRight topic: core status: verified
// verified behavior: Test.go(...) == true
namespace Test
func go() -> bool {
let d = 0
return d == 0 || (10 / d) > 0
}Runs `add` → 7u
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Uint_Add topic: core status: verified
// verified behavior: Test.add(...) == 7u
namespace Test
func add(a: uint, b: uint) -> uint { return a + b }Runs `go` → uint.MaxValue
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Uint_MaxValueConstant topic: core status: verified
// verified behavior: Test.go(...) == uint.MaxValue
namespace Test
func go() -> uint { return uint.MaxValue }Runs `mul` → 12u
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Uint_Multiply topic: core status: verified
// verified behavior: Test.mul(...) == 12u
namespace Test
func mul(a: uint, b: uint) -> uint { return a * b }Runs `add` → 7ul
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Ulong_Add topic: core status: verified
// verified behavior: Test.add(...) == 7ul
namespace Test
func add(a: ulong, b: ulong) -> ulong { return a + b }Runs `echo` → 18_000_000_000_000_000_000UL
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Ulong_LargeValue topic: core status: verified
// verified behavior: Test.echo(...) == 18_000_000_000_000_000_000UL
namespace Test
func echo(n: ulong) -> ulong { return n }Runs `null` → "hi"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_ExplicitInterface.cs::ExplicitMembers_TwoInterfaces_SameName topic: core status: verified
// verified behavior: Test.null(...) == "hi"
namespace Test
interface IReadInt { func read() -> int }
interface IReadStr { func read() -> string }
class Dual : IReadInt, IReadStr {
func IReadInt.read() -> int = 7
func IReadStr.read() -> string = "hi"
}
func make() -> Dual = Dual()Runs `go` → 42
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::CrossNamespace_BareFreeFunctionViaUsing topic: core status: verified
// verified behavior: Test.go(...) == 42
namespace Lib
func answer() -> int = 42Runs `go` → 42
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::CrossNamespace_QualifiedFreeFunctionCall topic: core status: verified
// verified behavior: Test.go(...) == 42
namespace MathNs
func add(a: int, b: int) -> int {
return a + b
}ILEmitterTests_Integration__CrossNamespace_QualifiedFreeFunctionReturningCollection
core runnable verifiedRuns `go` → 2
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::CrossNamespace_QualifiedFreeFunctionReturningCollection topic: core status: verified
// verified behavior: Test.go(...) == 2
namespace Lib.Inner
func seed() -> List<int> {
let xs = List<int>()
xs.Add(7)
xs.Add(8)
return xs
}ILEmitterTests_Integration__CrossNamespace_RefDataSameNamespacePromotionResolves
core runnable verified ×2Runs `go` → 99
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::CrossNamespace_RefDataSameNamespacePromotionResolves topic: core status: verified
// verified behavior: Test.go(...) == 99
namespace Bank
class Account {
var balance: int
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::Exe_EntryPointIsWiredToMain topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
pub class Program {
var counter: int
init() { self.counter = 0 }
func run() -> int {
for i in 1..5 {
self.counter += i
}
return self.counter
}
}
func main() -> int {
let p = Program()
return p.run()
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::Library_NoEntryPointEvenWithMain topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func main() -> int { return 5 }Runs `go` → "Object"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::Reflection_BaseTypeOfRefData topic: core status: verified
// verified behavior: Test.go(...) == "Object"
namespace Test
pub class Widget {
id: int
init(id: int) { self.id = id }
}
func go() -> string {
let w = Widget(1)
return w.GetType().BaseType.Name
}Runs `go` → "Widget"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::Reflection_RuntimeTypeName topic: core status: verified
// verified behavior: Test.go(...) == "Widget"
namespace Test
pub class Widget {
id: int
init(id: int) { self.id = id }
}
func go() -> string {
let w = Widget(7)
return w.GetType().Name
}Runs `go` → "Test"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::Reflection_TypeNamespace topic: core status: verified
// verified behavior: Test.go(...) == "Test"
namespace Test
pub class Widget {
id: int
init(id: int) { self.id = id }
}
func go() -> string {
let w = Widget(1)
return w.GetType().Namespace
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::Added_LiteralBracesPassThrough topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
return "{0}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::NegationUnaryInHole topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let b = true
return "not={!b}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::NoHolesPlainString topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string = "plain"Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::ParenthesizedHole topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let a = 3
let b = 4
return "r={(a + b) * 2}"
}Runs `go` → 8
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Nominal.cs::Added_InterfaceReturnedFromFunction topic: core status: verified
// verified behavior: Test.go(...) == 8
namespace Test
interface ISized { func size() -> int }
class Crate : ISized {
n: int
init(n: int) { self.n = n }
func size() -> int = self.n
}
func make() -> ISized = Crate(8)
func go() -> int { let s = make() return s.size() }Runs `go` → 7
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Nominal.cs::Added_RefData_DeclaresInterface_Works topic: core status: verified
// verified behavior: Test.go(...) == 7
namespace Test
interface ICounter { func get() -> int }
class Counter : ICounter {
value: int
init(v: int) { self.value = v }
func get() -> int = self.value
}
func read(c: ICounter) -> int = c.get()
func go() -> int { let c = Counter(7) return read(c) }Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PtrListRepro.cs::ListCtor_Alone_Resolves topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
let xs = List<int>()
xs.Add(5)
xs.Add(10)
var t = 0
for x in xs {
t += x
}
return t
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Receivers.cs::InlineMethod_Minimal_Class topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
class Foo { func Bar() { } }
func make() -> Foo = Foo()Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Returns.cs::NoReturnsClause_NoArrow_DefaultsToVoid topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
class Q {
n: int
init(n: int) { self.n = n }
func touch() { } // no -> Type, no returns clause: void
}
func go() {
let q = Q(0)
q.touch()
}ILEmitterTests_Returns__Returns_Clause_On_RefData_Bound_Method_Has_Correct_ReturnType
core unknown verifiedCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Returns.cs::Returns_Clause_On_RefData_Bound_Method_Has_Correct_ReturnType topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
class Q {
returns Q
n: int
init(n: int) { self.n = n }
func bump() { return Q(self.n + 1) }
}Runs `go` → 1
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Returns.cs::Returns_Clause_On_RefData_Explicit_Arrow_Wins topic: core status: verified
// verified behavior: Test.go(...) == 1
namespace Test
class Q {
returns Q
n: int
init(n: int) { self.n = n }
func bump() { return Q(self.n + 1) }
func count() -> int { return self.n }
}
func go() -> int {
let q = Q(0)
return q.bump().count()
}Runs `go` → 3
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Returns.cs::Returns_Clause_On_RefData_Fluent_Chaining topic: core status: verified
// verified behavior: Test.go(...) == 3
namespace Test
class Q {
returns Q
n: int
init(n: int) { self.n = n }
func bump() { return Q(self.n + 1) }
}
func go() -> int {
let q = Q(0)
let r = q.bump().bump().bump()
return r.n
}Runs `go` → 1
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Returns.cs::Returns_Clause_On_RefData_Sets_Default_For_Methods topic: core status: verified
// verified behavior: Test.go(...) == 1
namespace Test
class Q {
returns Q
n: int
init(n: int) { self.n = n }
func bump() { return Q(self.n + 1) }
}
func go() -> int {
let q = Q(0)
let r = q.bump()
return r.n
}