core — examples
← all topics · 698 examples · page 14 of 14 · raw source ↓
Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: MatchTypePatternTests.cs::AsOperator_SafeCast_ComposesWithNullable topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func go() -> int {
let s: Sym = TypeSym("a", 2)
let t = s as TypeSym
return t?.arity ?? 0
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: MatchTypePatternTests.cs::AsOperator_SafeCast_NilOnMiss topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func go() -> int {
let s: Sym = MethodSym("a", false)
let t = s as TypeSym
return t?.arity ?? 0
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: MatchTypePatternTests.cs::IsOperator_Test_And_Negation topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func go() -> int {
let s: Sym = TypeSym("a", 1)
if s is TypeSym { return 1 }
if s is not MethodSym { return 2 }
return 3
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: MatchTypePatternTests.cs::IsTarget_Nullable_IsRejected topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func f(o: object) -> bool = o is string?Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: MatchTypePatternTests.cs::TypePattern_Guard_FallsToNextArm topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func bazCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: MixedLanguageTests.cs::CSharp_Class_Constructed_In_Esharp topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func make(n: int) -> Box = Box(n)
func (b: Box) valueOf() -> int = b.NCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: MixedLanguageTests.cs::CSharp_Class_Field_Read_From_Esharp_Function topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func (v: Vec) sum() -> int = v.X + v.YCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: MixedLanguageTests.cs::CSharp_Ctor_With_Multiple_Args_Constructed_In_Esharp topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func make(x: int, y: int, label: string) -> Rect = Rect(x, y, label)
func (r: Rect) area() -> int = r.X * r.YCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: MixedLanguageTests.cs::CSharp_Enum_Switch_In_Esharp topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func label(c: Color) -> string {
if c == Color.Red {
return "red"
}
if c == Color.Green {
return "green"
}
return "other"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: MixedLanguageTests.cs::CSharp_Instance_Method_Called_From_Esharp topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func (g: Greeter) describe() -> string = g.Hello("world")Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: MixedLanguageTests.cs::CSharp_Property_Read_From_Esharp topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func (p: Person) name_of() -> string = p.NameCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: MixedLanguageTests.cs::CSharp_Static_Method_Called_From_Esharp topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func double_it(x: int) -> int = MathHelper.Twice(x)Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: MultiLineParamsTests.cs::Unclosed_ParamList_StillErrors topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func broken(a: int,Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: NarrowingTests.cs::FieldPath_LetField_NarrowsAcrossNoCall topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
class Box {
let item: Sym
init(i: Sym) { self.item = i }
}
func go() -> int {
let b = Box(TypeSym("a", 4))
if b.item is TypeSym { return b.item.arity }
return 0
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: NarrowingTests.cs::Rebind_Via_As_Works_OnVar topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func go() -> int {
var s: Sym = TypeSym("a", 1)
let t = s as TypeSym
return t?.arity ?? 0
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: NarrowingTests.cs::SmartCast_AndChain_NarrowsRightOperand topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let s: Sym = MethodSym("a", true)
if s is MethodSym && s.isStatic { return "yes" }
return "no"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: NarrowingTests.cs::SmartCast_Else_NarrowsOnNegativeOverClosed topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let s: Sym = MethodSym("m", false)
if s is TypeSym {
return "t"
} else {
return s.name
}
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: NarrowingTests.cs::SmartCast_GuardReturn_NarrowsRestOfBlock topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func go() -> int {
let s: Sym = TypeSym("a", 7)
if s is not TypeSym { return -1 }
return s.arity
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: NarrowingTests.cs::SmartCast_If_Is_ResolvesMember_NoRebind topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func go() -> int {
let s: Sym = TypeSym("a", 3)
if s is TypeSym { return s.arity }
return 0
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: OptionalArgTests.cs::BoolDefault_Used_When_Omitted topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> bool = Lib.flag()Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: OptionalArgTests.cs::CharDefault_Used_When_Omitted topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> string = Lib.repeat("ab")Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: OptionalArgTests.cs::ConstructorDefault_Used_When_Omitted topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
let c = Counter()
return c.Value
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: OptionalArgTests.cs::DoubleDefault_Used_When_Omitted topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> double = Lib.half(8.0)Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: OptionalArgTests.cs::EnumDefault_Used_When_Omitted topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int = Lib.withMode(10)Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: OptionalArgTests.cs::InstanceMethodDefault_Used_When_Omitted topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
let c = Counter(100)
return c.bump()
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: OptionalArgTests.cs::IntDefault_Overridden_When_Passed topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int = Lib.scale(5, 3)Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: OptionalArgTests.cs::IntDefault_Used_When_Omitted topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int = Lib.scale(5)Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: OptionalArgTests.cs::LongDefault_Used_When_Omitted topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> long = Lib.big()Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: OptionalArgTests.cs::MultipleDefaults_AllOmitted topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int = Lib.two()Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: OptionalArgTests.cs::MultipleDefaults_FirstPassed_SecondDefaulted topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int = Lib.two(7)Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: OptionalArgTests.cs::NullReferenceDefault_Used_When_Omitted topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int = Lib.lenOr()Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: OptionalArgTests.cs::StringDefault_Used_When_Omitted topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> string = Lib.label("hi")Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: PrimaryCtorCaptureTests.cs::Header_AssignToCapturedParam_IsError topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
class Svc(a: int) {
func bump() -> int {
a = a + 1
return a
}
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: RefChoiceCaseViewTests.cs::Json_Transparent_EndToEnd topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: SyntaxFidelityTests.cs::NodeSlice_OfUnmodifiedNode_IsVerbatimSource topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func g() -> int {
return a * (b + c)
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: SyntaxFidelityTests.cs::RealParsedNodes_HaveRealRanges topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func f() -> int { return abc + 1 }Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::ExplicitConformance_Missing_Method_Reports_Error topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
interface IRenderable {
func render() -> string
}
class Button : IRenderable {
label: string
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::Reports_Syntax_Diagnostics topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Broken
pub func nope( -> void {
return
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::Transpiles_Defer topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace IO
pub func process(path: string) -> string {
let file = File.Open(path)
defer { file.Close() }
return file.ReadAll()
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::Transpiles_Function_Literal topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace FnTest
func run(items: List<int>) {
items.Sort(func(a: int, b: int) -> int {
return a - b
})
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TypeGrammarTests.cs::ErrorMember_CarriesValidSpan topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
%%%
Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TypeGrammarTests.cs::Member_Unexpected_ReportsAndContinues topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
%%%
func go() -> int { return 1 }Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TypeGrammarTests.cs::MissingTypeName_ReportsAndRecovers topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go(x: ) -> int { return 1 }Rejected at compile time: ES0900
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TypeGrammarTests.cs::ParseError_GatesEmission topic: core status: unverified
// verified behavior: reports diagnostic ES0900
namespace Test
func go() -> int {
let x = ;
return 1
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TypeGrammarTests.cs::PromotedGeneric_BoolResult topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func go() -> bool {
let w = Wrap<int> { v: 9 }
return w.mapped((x) => x > 5).v
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TypeGrammarTests.cs::PromotedGeneric_CrossType_RoundTrip topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func go() -> int {
let w = Wrap<int> { v: 12 }
return w.mapped((x) => x.ToString()).mapped((s) => s.Length + 1).v
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TypeGrammarTests.cs::PromotedGeneric_StringReceiver_ToInt topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
func go() -> int {
let w = Wrap<string> { v: "hello" }
return w.mapped((s) => s.Length).v
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TypeGrammarTests.cs::ReturnType_ParsesStructurally topic: core status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace T
func f() -> List<(int, string)> { return [] }