core — examples
← all topics · 500 examples · page 3 of 10 · raw source ↓
Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Nested_ListOfList topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
let outer = List<List<int>>()
let inner = [1, 2, 3]
outer.Add(inner)
return outer[0].Count
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Nullable_HasValueViaCoalesce topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func maybe(present: bool) -> int? {
if present { return 100 }
return nil
}
func go() -> int {
let a = maybe(true) ?? 0
let b = maybe(false) ?? 0
return a + b
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Nullable_NilFallback topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func find(id: int) -> int? {
if id == 0 { return nil }
return 42
}
func go() -> int {
let v = find(0)
return v ?? -1
}Runs `go` → "fallback"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Nullable_RefTypeString topic: core status: verified
// verified behavior: Test.go(...) == "fallback"
namespace Test
func find(id: int) -> string? {
if id == 0 { return nil }
return "found"
}
func go() -> string {
return find(0) ?? "fallback"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Nullable_ValuePresent topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func find(id: int) -> int? {
if id == 0 { return nil }
return 42
}
func go() -> int {
let v = find(1)
return v ?? -1
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::RP_FuncParam_Invoke topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func apply(f: Func<string, string>, x: string) -> string = f(x)
func go() -> string = apply((s) => s + "!", "hi")ILEmitterTests_Coverage_Collections__RP_InterfaceInheritedMember_ReadOnlyListCount
core unknown verifiedCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::RP_InterfaceInheritedMember_ReadOnlyListCount topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
var xs = List<int>()
xs.Add(1)
xs.Add(2)
let ro: IReadOnlyList<int> = xs
return ro.Count
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::RP_OutParam_TryPattern topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func try_thing(input: int, out result: int) -> bool {
result = input + 1
return true
}
func go() -> int {
var r = 0
if try_thing(42, out r) { return r }
return -1
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::RP_StringEquals_OrdinalIgnoreCase topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> bool = string.Equals("Users", "users", StringComparison.OrdinalIgnoreCase)Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::RP_StringJoin_OverList topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> string {
var built = List<string>()
built.Add("a")
built.Add("b")
built.Add("c")
return string.Join('/', built)
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::RP_StringJoin_StringSeparator_OverList topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> string {
var xs = List<string>()
xs.Add("a")
xs.Add("b")
xs.Add("c")
return string.Join(", ", xs)
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::RP_TrimStart_Split_Count topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
let segs = "/users/42".TrimStart('/').Split('/', StringSplitOptions.RemoveEmptyEntries)
return segs.Length
}Runs `go` → "hello world"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::String_Concatenation topic: core status: verified
// verified behavior: Test.go(...) == "hello world"
namespace Test
func go() -> string {
let a = "hello"
let b = "world"
return a + " " + b
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::String_Contains topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> bool { return "hello world".Contains("world") }Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::String_EqualityComparison topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> bool {
let a = "abc"
let b = "abc"
return a == b
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::String_IndexOf topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int { return "hello world".IndexOf("world") }Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::String_Inequality topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> bool { return "abc" != "abd" }Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::String_Length topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int { return "hello".Length }Runs `go` → "hexxo"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::String_Replace topic: core status: verified
// verified behavior: Test.go(...) == "hexxo"
namespace Test
func go() -> string { return "hello".Replace("l", "x") }Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::String_StartsWith topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> bool { return "hello".StartsWith("he") }Runs `go` → "ell"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::String_Substring topic: core status: verified
// verified behavior: Test.go(...) == "ell"
namespace Test
func go() -> string { return "hello".Substring(1, 3) }Runs `go` → "HELLO"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::String_ToUpper topic: core status: verified
// verified behavior: Test.go(...) == "HELLO"
namespace Test
func go() -> string { return "hello".ToUpper() }Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::String_TrimAndEmpty topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int { return " ".Trim().Length }Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Tuple_DestructureInFor topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
let pairs = List<(int, int)>()
pairs.Add((10, 20))
pairs.Add((30, 0))
var total = 0
for (a, b) in pairs {
total += a + b
}
return total
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Tuple_DestructureInLet topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func swap(a: int, b: int) -> (int, int) {
return (b, a)
}
func go() -> int {
let (x, y) = swap(2, 1)
return x
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Tuple_ReturnFromFunc topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func swap(a: int, b: int) -> (int, int) {
return (b, a)
}
func go() -> int {
let t = swap(2, 3)
return t.Item1 + t.Item2
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Added_CompoundAssign_AllOps topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
var n = 10
n += 4
n -= 2
n *= 1
n /= 1
return n - 5
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Added_For_AccumulateString topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> string {
var s = ""
for i in 0..3 { s = s + "a" }
return s
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Added_For_RangeSum topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
var t = 0
for i in 0..5 { t += i }
return t
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Added_If_ElseIf_Chain topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func classify(n: int) -> int {
if n < 0 { return 0 }
else if n == 0 { return 1 }
else { return 2 }
}
func go() -> int { return classify(7) }Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Added_NestedWhile_Product topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
var t = 0
var i = 0
while i < 3 {
var j = 0
while j < 4 {
t += 1
j += 1
}
i += 1
}
return t
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Added_While_DecrementToZero topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
var n = 5
while n > 0 { n -= 1 }
return n
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::For_EarlyReturnFromLoop topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func indexOf(xs: List<int>, target: int) -> int {
var i = 0
for x in xs {
if x == target { return i }
i += 1
}
return -1
}
func go() -> int {
let xs = [10, 20, 30, 40]
return indexOf(xs, 40)
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::For_Nested_Ranges topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
var count = 0
for i in 0..3 {
for j in 0..3 {
count += 1
}
}
return count
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::For_NotFoundReturnsSentinel topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func indexOf(xs: List<int>, target: int) -> int {
var i = 0
for x in xs {
if x == target { return i }
i += 1
}
return -1
}
func go() -> int {
let xs = [10, 20, 30]
return indexOf(xs, 99)
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::For_OverListLiteral topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
var total = 0
for x in [10, 20, 30] {
total += x
}
return total
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::For_OverString_CountsVowels topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
let s = "hello"
var vowels = 0
for c in s {
if c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' {
vowels += 1
}
}
return vowels
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::For_Range_Exclusive topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
var total = 0
for i in 0..5 {
total += i
}
return total
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::For_Range_WithVariableBounds topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func sumRange(lo: int, hi: int) -> int {
var total = 0
for i in lo..hi {
total += i
}
return total
}
func go() -> int { return sumRange(3, 5) }Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::For_RangeBuildsProduct topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
var product = 1
for i in 1..6 {
product *= i
}
return product
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::If_AsGuard_NoElse_FallsThrough topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
var n = 7
if n < 0 { n = 0 }
return n
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::If_Else_TakesElseBranch topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
if 4 < 3 { return 1 } else { return 0 }
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::If_Nested topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
let a = 5
let b = 10
if a > 0 {
if b > 0 {
return 42
}
}
return 0
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::If_ReturnsValueFromBothBranches topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func pickLarger(a: int, b: int) -> int {
if a > b { return a } else { return b }
}
func go() -> int { return pickLarger(100, 50) }Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::If_TakesThenBranch topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
if 3 < 4 { return 1 }
return 0
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::IfElseIf_Chain_PicksMiddle topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func classify(n: int) -> int {
if n < 0 { return 1 }
else if n == 0 { return 2 }
else { return 3 }
}
func go() -> int { return classify(0) }Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::LetElse_BindsOnPresent topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func find(id: int) -> int? {
if id == 0 { return nil }
return 5
}
func go() -> int {
let v = find(1) else { return -1 }
return v
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::LetElse_TakesElseOnNil topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func find(id: int) -> int? {
if id == 0 { return nil }
return 5
}
func go() -> int {
let v = find(0) else { return -1 }
return v
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Loop_AccumulateMaxValue topic: core status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
let xs = [10, 40, 25, 5, 30]
var best = xs[0]
for x in xs {
if x > best { best = x }
}
return best
}Runs `go` → "fallback"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::NullCoalescing_AllNilUsesFallback topic: core status: verified
// verified behavior: Test.go(...) == "fallback"
namespace Test
func pick(a: string?, b: string?) -> string {
return a ?? b ?? "fallback"
}
func go() -> string { return pick(nil, nil) }