core — examples
← all topics · 698 examples · page 13 of 14 · raw source ↓
Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::Json_ComputesNestingDepth topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func go() -> int {
let r = parse("[1, [2, [3, 4]]]")
if r.IsError { return -1 }
return depth(r.Value)
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::Json_CountsAllNodes topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func go() -> int {
let r = parse("[1, [2, 3], 4]")
if r.IsError { return -1 }
return countNodes(r.Value)
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::Json_EmptyArray topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func go() -> int {
let r = parse("[]")
if r.IsError { return -1 }
return countNodes(r.Value)
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::Json_NegativeNumbers topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func go() -> int {
let r = parse("[-2, -3]")
if r.IsError { return 999 }
return sumNumbers(r.Value)
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::Json_SumIgnoresNonNumbers topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func go() -> int {
let r = parse("[1, true, \"hi\", null, [2, 3]]")
if r.IsError { return -1 }
return sumNumbers(r.Value)
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::Json_SumsNestedNumbers topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func go() -> int {
let r = parse("[1, [2, 3], 4]")
if r.IsError { return -1 }
return sumNumbers(r.Value)
}Runs `go` → "unterminated array"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::Json_UnterminatedArrayIsError topic: core status: unverified
// verified behavior: Test.go(...) == "unterminated array"
func go() -> string {
let r = parse("[1, 2")
return r.IsError ? r.Error : "ok"
}Runs `go` → "unterminated string"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::Json_UnterminatedStringIsError topic: core status: unverified
// verified behavior: Test.go(...) == "unterminated string"
func go() -> string {
let r = parse("\"abc")
return r.IsError ? r.Error : "ok"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::Json_WhitespaceTolerant topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func go() -> int {
let r = parse(" [ 1 ,\t2 ,\n 3 ] ")
if r.IsError { return -1 }
return sumNumbers(r.Value)
}Runs `go` → 41
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PtrEmbedIface.cs::PointerEmbed_BumpOnceThenValue topic: core status: unverified
// verified behavior: Test.go(...) == 41
func once(b: IBumper) -> int {
b.bump()
return b.value()
}
Runs `go` → "n=42"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PtrEmbedIface.cs::PointerEmbed_TwiceThenInterpolate topic: core status: unverified
// verified behavior: Test.go(...) == "n=42"
func twice(b: IBumper) -> int {
b.bump()
b.bump()
return b.value()
}
Runs `go` → 40
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PtrEmbedIface.cs::PointerEmbed_ValueReadOnly topic: core status: unverified
// verified behavior: Test.go(...) == 40
func read(b: IBumper) -> int = b.value()
Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Returns.cs::Returns_As_Signature_Synonym_Is_Rejected topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func add(a: int, b: int) returns int { return a + b }Runs `go` → 10
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::G01_UnwrapOr_Ok topic: core status: unverified
// verified behavior: Test.go(...) == 10
func go() -> int = parse(10).UnwrapOr(7)Runs `go` → 7
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::G02_UnwrapOr_Err topic: core status: unverified
// verified behavior: Test.go(...) == 7
func go() -> int = parse(-1).UnwrapOr(7)Runs `go` → 10
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::G03_Unwrap_Ok topic: core status: unverified
// verified behavior: Test.go(...) == 10
func go() -> int = parse(10).Unwrap()Runs `go` → "neg"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::G04_UnwrapErr_Err topic: core status: unverified
// verified behavior: Test.go(...) == "neg"
func go() -> string = parse(-1).UnwrapErr()Runs `go` → 3
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::G05_UnwrapOrElse_Err topic: core status: unverified
// verified behavior: Test.go(...) == 3
func go() -> int = parse(-1).UnwrapOrElse((e) => e.Length)Runs `go` → 10
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::G06_UnwrapOrElse_Ok topic: core status: unverified
// verified behavior: Test.go(...) == 10
func go() -> int = parse(10).UnwrapOrElse((e) => e.Length)Runs `go` → 15
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::G07_Map_Ok_ThenUnwrap topic: core status: unverified
// verified behavior: Test.go(...) == 15
func go() -> int = parse(10).Map((x) => x + 5).Unwrap()Runs `go` → 99
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::G08_Map_Err_Passthrough topic: core status: unverified
// verified behavior: Test.go(...) == 99
func go() -> int = parse(-1).Map((x) => x + 5).UnwrapOr(99)Runs `go` → "n10"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::G09_Map_ToString_TNewIsString topic: core status: unverified
// verified behavior: Test.go(...) == "n10"
func go() -> string = parse(10).Map((x) => "n" + x.ToString()).UnwrapOr("z")Runs `go` → 3
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::G10_MapErr_Err_TNewIsInt topic: core status: unverified
// verified behavior: Test.go(...) == 3
func go() -> int = parse(-1).MapErr((e) => e.Length).UnwrapErr()Runs `go` → 10
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::G11_MapErr_Ok_Passthrough topic: core status: unverified
// verified behavior: Test.go(...) == 10
func go() -> int = parse(10).MapErr((e) => e.Length).UnwrapOr(0)Runs `go` → 20
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::G12_Bind_Ok_Chains topic: core status: unverified
// verified behavior: Test.go(...) == 20
func go() -> int = parse(10).Bind((x) => parse(x * 2)).Unwrap()Runs `go` → 42
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::G13_Bind_Err_ShortCircuits topic: core status: unverified
// verified behavior: Test.go(...) == 42
func go() -> int = parse(-1).Bind((x) => parse(x * 2)).UnwrapOr(42)Runs `go` → 11
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::G14_Match_Ok topic: core status: unverified
// verified behavior: Test.go(...) == 11
func go() -> int = parse(10).Match((v) => v + 1, (e) => -1)Runs `go` → -1
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::G15_Match_Err topic: core status: unverified
// verified behavior: Test.go(...) == -1
func go() -> int = parse(-1).Match((v) => v + 1, (e) => -1)Runs `go` → 22
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::G16_Map_Chain topic: core status: unverified
// verified behavior: Test.go(...) == 22
func go() -> int = parse(10).Map((x) => x + 1).Map((x) => x * 2).UnwrapOr(0)Runs `go` → 111
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::G17_Map_InArithmetic topic: core status: unverified
// verified behavior: Test.go(...) == 111
func go() -> int {
let m = parse(10).Map((x) => x + 1)
return m.UnwrapOr(0) + 100
}Runs `go` → 42
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::G18_Map_Then_Bind topic: core status: unverified
// verified behavior: Test.go(...) == 42
func go() -> int = parse(10).Map((x) => x + 11).Bind((x) => parse(x * 2)).Unwrap()Runs `go` → 10
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::G19_Inspect_Passthrough topic: core status: unverified
// verified behavior: Test.go(...) == 10
func go() -> int = parse(10).Inspect((v) => Console.Out.Write("")).UnwrapOr(0)Runs `go` → 7
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::G20_InspectErr_Passthrough topic: core status: unverified
// verified behavior: Test.go(...) == 7
func go() -> int = parse(-1).InspectErr((e) => Console.Out.Write("")).UnwrapOr(7)Runs `go` → 3
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::I01_Map_ToString_Length topic: core status: unverified
// verified behavior: Test.go(...) == 3
func go() -> int = parse(10).Map((x) => "n" + x.ToString()).UnwrapOr("").LengthRuns `go` → 43
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::I02_Map_Twice_Arithmetic topic: core status: unverified
// verified behavior: Test.go(...) == 43
func go() -> int = parse(10).Map((x) => x * 2).Map((x) => x + 3).UnwrapOr(0) + 20Runs `go` → 3
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::I05_MapErr_Then_Match topic: core status: unverified
// verified behavior: Test.go(...) == 3
func go() -> int = parse(-1).MapErr((e) => e.Length).Match((v) => v, (e) => e)Runs `go` → 20
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::I06_Match_Ok_Branch topic: core status: unverified
// verified behavior: Test.go(...) == 20
func go() -> int = parse(10).Match((v) => v * 2, (e) => -1)Runs `go` → 13
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::I09_Unwrap_Ok_InArithmetic topic: core status: unverified
// verified behavior: Test.go(...) == 13
func go() -> int = parse(10).Unwrap() + 3Runs `go` → 7
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::I11_StaticOk_Value topic: core status: unverified
// verified behavior: Test.go(...) == 7
namespace Test
using "Esharp.Stdlib"
func go() -> int = Result.Ok<int, string>(7).ValueRuns `go` → "boom"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::I12_StaticError_Payload topic: core status: unverified
// verified behavior: Test.go(...) == "boom"
namespace Test
using "Esharp.Stdlib"
func go() -> string = Result.Error<int, string>("boom").ErrorRuns `go` → true
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::I13_StaticOk_IsOk topic: core status: unverified
// verified behavior: Test.go(...) == true
namespace Test
using "Esharp.Stdlib"
func go() -> bool = Result.Ok<int, string>(7).IsOkRuns `go` → true
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::I14_StaticError_IsError topic: core status: unverified
// verified behavior: Test.go(...) == true
namespace Test
using "Esharp.Stdlib"
func go() -> bool = Result.Error<int, string>("e").IsErrorRuns `go` → 8
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::I15_StaticOk_ThenMap topic: core status: unverified
// verified behavior: Test.go(...) == 8
namespace Test
using "Esharp.Stdlib"
func go() -> int = Result.Ok<int, string>(7).Map((x) => x + 1).UnwrapOr(0)Runs `go` → 8
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::J01_PromotedGeneric_IntToInt topic: core status: unverified
// verified behavior: Test.go(...) == 8
func go() -> int {
let w = Wrap<int> { v: 3 }
return w.mapped((x) => x + 5).v
}Runs `go` → 2
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::J02_PromotedGeneric_IntToString topic: core status: unverified
// verified behavior: Test.go(...) == 2
func go() -> int {
let w = Wrap<int> { v: 7 }
return w.mapped((x) => "n" + x.ToString()).v.Length
}Runs `go` → 16
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::J03_PromotedGeneric_Chained topic: core status: unverified
// verified behavior: Test.go(...) == 16
func go() -> int {
let w = Wrap<int> { v: 3 }
return w.mapped((x) => x + 5).mapped((y) => y * 2).v
}Rejected at compile time: ES2130
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_TaskFunc.cs::RegularFunc_Var_Capture_Is_Not_ES2130 topic: core status: unverified
// verified behavior: reports diagnostic ES2130
namespace Test
func go() {
var counter = 0
let bump = func() { counter = counter + 1 }
bump()
}Rejected at compile time: ES2145
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: IndexDiagnosticTests.cs::IndexingList_DoesNotError topic: core status: unverified
// verified behavior: reports diagnostic ES2145
namespace Test
func f(xs: List<int>) -> int { return xs[0] }Rejected at compile time: ES2145
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: IndexDiagnosticTests.cs::IndexingString_DoesNotError topic: core status: unverified
// verified behavior: reports diagnostic ES2145
namespace Test
func first(s: string) -> char { return s[0] }Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: MatchTypePatternTests.cs::AsBang_AssertingCast_Reference topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let s: Sym = TypeSym("z", 9)
let t = s as! TypeSym
return t.name
}