Skip to content

core — examples

← all topics · 500 examples · page 6 of 10 · raw source ↓

Runs `go` → 20

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_ParenthesizedPrecedence   topic: core   status: verified
// verified behavior: Test.go(...) == 20

namespace Test
func go() -> int { return (2 + 3) * 4 }

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 `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
}

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 }

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` → 40

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PtrEmbedIface.cs::PointerEmbed_ValueReadOnly   topic: core   status: verified
// 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_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
}

Runs `go` → 11

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Returns.cs::Returns_Is_Still_Valid_Identifier_Elsewhere   topic: core   status: verified
// verified behavior: Test.go(...) == 11

namespace Test

func go(returns: int) -> int { return returns + 1 }

Runs `sum` → 3

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Returns.cs::Returns_Keyword_Mixed_With_Arrow_In_Same_File   topic: core   status: verified
// verified behavior: Test.sum(...) == 3

namespace Test

func a() -> int { return 1 }
func b() returns int { return 2 }
func sum() returns int { return a() + b() }

Runs `go` → 5

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Returns.cs::Returns_Keyword_Synonym_For_Arrow_TopLevel   topic: core   status: verified
// verified behavior: Test.go(...) == 5

namespace Test

func add(a: int, b: int) returns int { return a + b }

func go() returns int { return add(2, 3) }

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Returns.cs::Returns_Keyword_Synonym_With_Nullable_Return   topic: core   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test

func maybe() returns int? { return nil }

Runs `greet` → "hi world"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Returns.cs::Returns_Keyword_Synonym_With_String_Return   topic: core   status: verified
// verified behavior: Test.greet(...) == "hi world"

namespace Test

func greet(name: string) returns string { return "hi " + name }

Runs `test` → 42

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

namespace Test

func test() returns int = 42

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StringEquality.cs::ChainedEquality   topic: core   status: verified
// verified behavior: Test.go(...) == true

func go() -> bool {
  let a = "a"
  let b = "a"
  let c = "a"
  return a == b && b == c
}

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StringEquality.cs::CharComparisonNotEqual   topic: core   status: verified
// verified behavior: Test.go(...) == true

func go() -> bool {
  let s = "abc"
  return s[0] != 'z'
}

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StringEquality.cs::CharComparisonStillCeq   topic: core   status: verified
// verified behavior: Test.go(...) == true

func go() -> bool {
  let s = "a b"
  return s[1] == ' '
}

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StringEquality.cs::ConcatEqualsLiteral   topic: core   status: verified
// verified behavior: Test.go(...) == true

func go() -> bool {
  let a = "ab"
  let b = "a" + "b"
  return a == b
}

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StringEquality.cs::EmptyStringEquality   topic: core   status: verified
// verified behavior: Test.go(...) == true

func go() -> bool {
  let a = ""
  let b = "x".Substring(0, 0)
  return a == b
}

Runs `go` → false

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StringEquality.cs::EqualityFeedingReturn   topic: core   status: verified
// verified behavior: Test.go(...) == false

func go() -> bool {
  let a = "abc"
  let b = "abd"
  return a == b
}

Runs `go` → 1

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StringEquality.cs::EqualityInIfCondition   topic: core   status: verified
// verified behavior: Test.go(...) == 1

func classify(s: string) -> int {
  if s == "fail" { return 1 }
  return 0
}
func go() -> int = classify("fail")

Runs `go` → 0

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StringEquality.cs::EqualityInIfCondition_NotTaken   topic: core   status: verified
// verified behavior: Test.go(...) == 0

func classify(s: string) -> int {
  if s == "fail" { return 1 }
  return 0
}
func go() -> int = classify("ok")