// ── ErrorPropagationTests__ForKV_MaxByValue ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ErrorPropagationTests.cs::ForKV_MaxByValue topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test using "System.Collections.Generic" func go() -> string { let d = Dictionary() d["a"] = 3 d["b"] = 9 d["c"] = 5 var best = "" var bestN = 0 for (k, v) in d { if v > bestN { bestN = v best = k } } return best } // ── ErrorPropagationTests__ForKV_SumsValues ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ErrorPropagationTests.cs::ForKV_SumsValues topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test using "System.Collections.Generic" func go() -> int { let d = Dictionary() d["a"] = 10 d["b"] = 20 d["c"] = 30 var sum = 0 for (k, v) in d { sum += v } return sum } // ── ErrorPropagationTests__ForKV_UsesKey ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ErrorPropagationTests.cs::ForKV_UsesKey topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test using "System.Collections.Generic" func go() -> int { let d = Dictionary() d["xy"] = 1 d["z"] = 1 var totalKeyLen = 0 for (k, v) in d { totalKeyLen += k.Length } return totalKeyLen } // ── ILEmitterTests__GenericConstructorCall_InFunction_IL ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests.cs::GenericConstructorCall_InFunction_IL topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test func make() -> string { let d = Dictionary() return "ok" } // ── ILEmitterTests__GenericConstructorCall_InInit_ParsesAndBinds ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests.cs::GenericConstructorCall_InInit_ParsesAndBinds topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test ref data Store { items: List lookup: Dictionary init() { self.items = List() self.lookup = Dictionary() } } // ── ILEmitterTests__GenericConstructorCall_Nested_ParsesCorrectly ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests.cs::GenericConstructorCall_Nested_ParsesCorrectly topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test func make() -> int { let m = Dictionary>() return 0 } // ── ILEmitterTests__GenericConstructorCall_Parser_ParsesCorrectly ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests.cs::GenericConstructorCall_Parser_ParsesCorrectly topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test func make() -> int { let d = Dictionary() return 0 } // ── ILEmitterTests__GenericExternalType_Dictionary_ResolvesCorrectly ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests.cs::GenericExternalType_Dictionary_ResolvesCorrectly topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test data Lookup { entries: Dictionary } // ── ILEmitterTests__GenericExternalType_Nested_ResolvesCorrectly ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests.cs::GenericExternalType_Nested_ResolvesCorrectly topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test data Nested { mapping: Dictionary> } // ── ILEmitterTests__Indexer_DictionaryGetSet_StringIntRoundTrip ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests.cs::Indexer_DictionaryGetSet_StringIntRoundTrip topic: interop status: verified // verified behavior: Test.run(...) == 185 namespace Test func run() -> int { let scores = Dictionary() scores["alice"] = 100 scores["bob"] = 85 return scores["alice"] + scores["bob"] } // ── ILEmitterTests__Out_DictionaryTryGetValue ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests.cs::Out_DictionaryTryGetValue topic: interop status: verified // verified behavior: Test.run(...) == 100 namespace Test func run() -> int { let scores = Dictionary() scores["alice"] = 100 if scores.TryGetValue("alice", out var score) { return score } return -1 } // ── ILEmitterTests__Property_SetOnBclObject_StringBuilderCapacity ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests.cs::Property_SetOnBclObject_StringBuilderCapacity topic: interop status: verified // verified behavior: Test.run(...) == 128 namespace Test func run() -> int { let sb = StringBuilder() sb.Capacity = 128 return sb.Capacity } // ── ILEmitterTests_Coverage_Adversarial__Generics_DictionaryStringToValueData ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Coverage_Adversarial.cs::Generics_DictionaryStringToValueData topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test data Score { points: int } func go() -> int { let m = Dictionary() m["a"] = Score { points: 5 } m["b"] = Score { points: 9 } return m["a"].points + m["b"].points } // ── ILEmitterTests_Coverage_Adversarial__Reflection_CountDeclaredMethodsViaInstanceType ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Coverage_Adversarial.cs::Reflection_CountDeclaredMethodsViaInstanceType topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test using "System.Reflection" data Widget { id: int } func go() -> bool { let w = Widget { id: 1 } let methods = w.GetType().GetMethods() return methods.Length >= 1 } // ── ILEmitterTests_Coverage_Collections__Added_DictStringToInt ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Coverage_Collections.cs::Added_DictStringToInt topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test func go() -> int { var m = Dictionary() m["a"] = 3 return m["a"] } // ── ILEmitterTests_Coverage_Collections__Algo_StringBuilderAccumulate ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Coverage_Collections.cs::Algo_StringBuilderAccumulate topic: interop status: verified // verified behavior: Test.go(...) == "0123" namespace Test func go() -> string { let sb = StringBuilder() for i in 0..4 { sb.Append(i.ToString()) } return sb.ToString() } // ── ILEmitterTests_Coverage_Collections__Dict_ContainsKey ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Coverage_Collections.cs::Dict_ContainsKey topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test func go() -> bool { let d = Dictionary() d["k"] = 1 return d.ContainsKey("k") } // ── ILEmitterTests_Coverage_Collections__Dict_Count ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Coverage_Collections.cs::Dict_Count topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test func go() -> int { let d = Dictionary() d["a"] = 1 d["b"] = 2 return d.Count } // ── ILEmitterTests_Coverage_Collections__Dict_IntKey ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Coverage_Collections.cs::Dict_IntKey topic: interop status: verified // verified behavior: Test.go(...) == "hello" namespace Test func go() -> string { let d = Dictionary() d[1] = "hello" return d[1] } // ── ILEmitterTests_Coverage_Collections__Dict_OverwriteValue ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Coverage_Collections.cs::Dict_OverwriteValue topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test func go() -> int { let d = Dictionary() d["k"] = 1 d["k"] = 2 return d["k"] } // ── ILEmitterTests_Coverage_Collections__Dict_TryGetValue ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Coverage_Collections.cs::Dict_TryGetValue topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test func go() -> int { let d = Dictionary() d["k"] = 7 if d.TryGetValue("k", out var v) { return v } return -1 } // ── ILEmitterTests_Coverage_Collections__Nested_DictOfList ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Coverage_Collections.cs::Nested_DictOfList topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test func go() -> int { let d = Dictionary>() d["nums"] = [10, 20] return d["nums"].Count } // ── ILEmitterTests_Coverage_Collections__RP_Dict_ComparerCtor_IsCaseInsensitive ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Coverage_Collections.cs::RP_Dict_ComparerCtor_IsCaseInsensitive topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test func go() -> int { var d = Dictionary(StringComparer.OrdinalIgnoreCase) d["A"] = "1" d["a"] = "2" return d.Count } // ── ILEmitterTests_Coverage_Collections__RP_NilDict_ReassignThenSet ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Coverage_Collections.cs::RP_NilDict_ReassignThenSet topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test func go() -> int { var d: Dictionary = nil if d == nil { d = Dictionary() } d["k"] = "v" return d.Count } // ── ILEmitterTests_Coverage_Collections__RP_ReadOnlyDict_CovariantAssign_AndCount ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Coverage_Collections.cs::RP_ReadOnlyDict_CovariantAssign_AndCount topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test func go() -> int { var d = Dictionary() d["a"] = "x" d["b"] = "y" let ro: IReadOnlyDictionary = d return ro.Count } // ── ILEmitterTests_Coverage_Data__Dictionary_PutGet ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Coverage_Data.cs::Dictionary_PutGet topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test func go() -> int { let d = Dictionary() d["answer"] = 42 return d["answer"] } // ── ILEmitterTests_Coverage_Misc__Bcl_StringBuilder ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Coverage_Misc.cs::Bcl_StringBuilder topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test func go() -> int { let sb = StringBuilder() sb.Append("foo") sb.Append("bar") return sb.ToString().Length } // ── ILEmitterTests_Coverage_Numerics__Double_Parse ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Coverage_Numerics.cs::Double_Parse topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test using "System.Globalization" func go() -> double { return double.Parse("3.14", CultureInfo.InvariantCulture) } // ── ILEmitterTests_ExternalReflection__AmbiguousExternalType_AcrossImports_ReportsES2151 ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_ExternalReflection.cs::AmbiguousExternalType_AcrossImports_ReportsES2151 topic: interop status: verified // verified behavior: reports diagnostic ES2151 namespace Test using "System.Threading" using "System.Timers" func go() -> int { let t = Timer() return 0 } // ── ILEmitterTests_ExternalReflection__IReadOnlyListInt_Count_AsInt ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_ExternalReflection.cs::IReadOnlyListInt_Count_AsInt topic: interop status: verified // verified behavior: Test.go(...) == 2 namespace Test func makeList() -> IReadOnlyList { let xs = List() xs.Add(1) xs.Add(2) return xs } func go() -> int { let ro = makeList() return ro.Count } // ── ILEmitterTests_ExternalReflection__IReadOnlyListInt_Count_Interpolated ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_ExternalReflection.cs::IReadOnlyListInt_Count_Interpolated topic: interop status: verified // verified behavior: Test.go(...) == "n=1" namespace Test func makeList() -> IReadOnlyList { let xs = List() xs.Add(7) return xs } func go() -> string { let ro = makeList() return "n={ro.Count}" } // ── ILEmitterTests_ExternalReflection__IReadOnlyListInt_Count_PassedAsCallArg ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_ExternalReflection.cs::IReadOnlyListInt_Count_PassedAsCallArg topic: interop status: verified // verified behavior: Test.go(...) == "2" namespace Test using "System.Text" func makeList() -> IReadOnlyList { let xs = List() xs.Add(2) xs.Add(5) return xs } func go() -> string { let ro = makeList() let sb = StringBuilder() sb.Append(ro.Count) return sb.ToString() } // ── ILEmitterTests_ExternalReflection__ListInt_Count_AsInt ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_ExternalReflection.cs::ListInt_Count_AsInt topic: interop status: verified // verified behavior: Test.go(...) == 3 namespace Test func go() -> int { let xs = List() xs.Add(1) xs.Add(2) xs.Add(3) return xs.Count } // ── ILEmitterTests_ExternalReflection__ListInt_Count_Interpolated ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_ExternalReflection.cs::ListInt_Count_Interpolated topic: interop status: verified // verified behavior: Test.go(...) == "count=2" namespace Test func go() -> string { let xs = List() xs.Add(1) xs.Add(2) return "count={xs.Count}" } // ── ILEmitterTests_ExternalReflection__ListObject_BoxInt_ReadBackElement ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_ExternalReflection.cs::ListObject_BoxInt_ReadBackElement topic: interop status: verified // verified behavior: Test.go(...) == 1 namespace Test func go() -> int { let xs = List() xs.Add(42) let arr = xs.ToArray() return arr.Length } // ── ILEmitterTests_ExternalReflection__ListObject_BoxInt_ToArray_Length ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_ExternalReflection.cs::ListObject_BoxInt_ToArray_Length topic: interop status: verified // verified behavior: Test.go(...) == 2 namespace Test func go() -> int { let xs = List() xs.Add(10) xs.Add(20) let arr = xs.ToArray() return arr.Length } // ── ILEmitterTests_ExternalReflection__MultiSegmentQualifiedStaticCall_Works ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_ExternalReflection.cs::MultiSegmentQualifiedStaticCall_Works topic: interop status: verified // verified behavior: Test.go(...) == ".txt" namespace Test func go() -> string { return System.IO.Path.GetExtension("file.txt") } // ── ILEmitterTests_ExternalReflection__OfType_ExplicitGenericArg_FiltersHeterogeneousList ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_ExternalReflection.cs::OfType_ExplicitGenericArg_FiltersHeterogeneousList topic: interop status: verified // verified behavior: Test.go(...) == 4 namespace Test func go() -> int { let xs = List() xs.Add(1) xs.Add("two") xs.Add(3) xs.Add("four") var sum = 0 for n in xs.OfType() { sum += n } return sum } // ── ILEmitterTests_ExternalReflection__OfType_ResultElementType_AllowsMemberAccess ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_ExternalReflection.cs::OfType_ResultElementType_AllowsMemberAccess topic: interop status: verified // verified behavior: Test.go(...) == 5 namespace Test func go() -> int { let xs = List() xs.Add("ab") xs.Add(7) xs.Add("cde") var total = 0 for s in xs.OfType() { total += s.Length } return total } // ── ILEmitterTests_ExternalReflection__QualifiedConstruction_External_Works ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_ExternalReflection.cs::QualifiedConstruction_External_Works topic: interop status: verified // verified behavior: Test.go(...) == 2 namespace Test func go() -> int { let sb = System.Text.StringBuilder() sb.Append(42) return sb.Length } // ── ILEmitterTests_ExternalReflection__TypeAlias_Construction_Works ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_ExternalReflection.cs::TypeAlias_Construction_Works topic: interop status: verified // verified behavior: Test.go(...) == 2 namespace Test using SB = "System.Text.StringBuilder" func go() -> int { let sb = SB() sb.Append(42) return sb.Length } // ── ILEmitterTests_ExternalReflection__TypeAlias_ParameterPosition_Works ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_ExternalReflection.cs::TypeAlias_ParameterPosition_Works topic: interop status: verified // verified behavior: Test.go(...) == 5 namespace Test using SB = "System.Text.StringBuilder" func length(b: SB) -> int = b.Length func go() -> int { let sb = SB() sb.Append("hello") return length(sb) } // ── ILEmitterTests_ExternalReflection__TypeAlias_ResolvesCollision ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_ExternalReflection.cs::TypeAlias_ResolvesCollision topic: interop status: verified // verified behavior: Test.go(...) == 3.0 namespace Test using "System.Threading" using TTimer = "System.Timers.Timer" func go() -> double { let t = TTimer() t.Interval = 3.0 return t.Interval } // ── ILEmitterTests_ExternalReflection__UsingStaticMultiSegment_BareCall_Works ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_ExternalReflection.cs::UsingStaticMultiSegment_BareCall_Works topic: interop status: verified // verified behavior: Test.go(...) == ".txt" namespace Test using static "System.IO.Path" func go() -> string { return GetExtension("file.txt") } // ── ILEmitterTests_Integration__PerFileImportScoping_BareExternalNameResolvesToOwnFileImport ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Integration.cs::PerFileImportScoping_BareExternalNameResolvesToOwnFileImport topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test using "System.Timers" func ta(x: Timer) -> int = 1 // ── ILEmitterTests_Integration__Reflection_AssemblyContainsTypes ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Integration.cs::Reflection_AssemblyContainsTypes topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test using "System.Reflection" data Marker { v: int } func go() -> bool { let t = Marker { v: 1 } let asm = t.GetType().Assembly return asm.GetTypes().Length > 0 } // ── ILEmitterTests_Interop__ArrowLambda_InfersParameterType ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Interop.cs::ArrowLambda_InfersParameterType topic: interop status: verified // verified behavior: Test.run(...) == 7 namespace Test func apply(x: int, f: Func) -> int { return f(x) } func run() -> int { return apply(5, (x) => x + 2) } // ── ILEmitterTests_Interop__ArrowLambda_TypedParameter ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Interop.cs::ArrowLambda_TypedParameter topic: interop status: verified // verified behavior: Test.run(...) == "ok" namespace Test func applyText(f: Func) -> string { return f("ok") } func run() -> string { return applyText((value: string) => value) } // ── ILEmitterTests_Interop__ArrowLambda_ZeroArgMultiArgCaptures ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Interop.cs::ArrowLambda_ZeroArgMultiArgCaptures topic: interop status: verified // verified behavior: Test.run(...) == 19 namespace Test func compute(f: Func) -> int { return f() } func combine(f: Func) -> int { return f(3, 4) } func run() -> int { let offset = 5 let left = compute(() => 7) let right = combine((x, y) => x + y + offset) return left + right } // ── ILEmitterTests_Interop__ForIn_ListOfInt_SumsElements ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Interop.cs::ForIn_ListOfInt_SumsElements topic: interop status: verified // verified behavior: Test.run(...) == 60 namespace Test func run() -> int { let xs = [10, 20, 30] var total = 0 for x in xs { total += x } return total } // ── ILEmitterTests_Interop__ImportStatic_MathMax ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Interop.cs::ImportStatic_MathMax topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test using static "System.Math" func run() -> double { return Max(2.5, 4.5) } // ── ILEmitterTests_Interop__JsonSerializer_Serialize ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Interop.cs::JsonSerializer_Serialize topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test using "System.Text.Json" func run() -> string { return JsonSerializer.Serialize("hello") } // ── TranspilerTests__Transpiles_Import_Directive ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: TranspilerTests.cs::Transpiles_Import_Directive topic: interop status: verified // compiles cleanly (no auto-run claim was extracted) namespace Test using "System.IO" using "MyNamespace" pub func run() { Console.WriteLine("hello") } // ── wordcount ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: wordcount.es topic: interop status: verified // hand-authored, idiomatic E# — verified through the E# compiler namespace Demo using "System.Collections.Generic" // Dictionary // ═════════════════════════════════════════════════════════════════════════════ // Counting word frequencies — a tour of BCL interop, which is the soul of E#. // // There is no bespoke E# hash map: you reach straight for `Dictionary` // from the .NET base class library and call it directly — `ContainsKey`, the `[key]` // indexer for get and set, `Count`, `TryGetValue` with an `out` parameter. E# adds no // wrapper; a `Dictionary` here is the same `Dictionary` a C# caller would hand you. // `string.Split`, `.ToLower()`, and `.Length` are likewise just the BCL string API. // // The program reads a sentence, tallies each word, then finds the most frequent one // — a single pass to count, a single pass to pick the winner. `out` is the idiomatic // BCL "return a bool and a value" shape, and E# speaks it natively (`out var n`). // ═════════════════════════════════════════════════════════════════════════════ // Tally how many times each (lower-cased) word appears. Returns the populated map. func tally(text: string) -> Dictionary { let counts = Dictionary() let words = text.ToLower().Split(' ') var i = 0 while i < words.Length { let w = words[i] if w.Length > 0 { // get-or-zero then store back: the indexer reads and writes the same cell. if counts.ContainsKey(w) { counts[w] = counts[w] + 1 } else { counts[w] = 1 } } i += 1 } return counts } // How many times one word occurs, using the BCL `TryGetValue(key, out value)` pattern. // `out n` binds a fresh local the call fills; reading `n` afterward is the count (or 0 // when the word is absent and the call returned false). func frequency(counts: Dictionary, word: string) -> int { if counts.TryGetValue(word, out var n) { return n } return 0 } // Walk the entries to find the highest count. `for (k, v) in dict` destructures each // KeyValuePair into its key and value — tuple-style iteration over a BCL collection. func mostFrequentCount(counts: Dictionary) -> int { var best = 0 for (word, n) in counts { if n > best { best = n } } return best } // "the cat sat on the mat the cat ran" — "the" appears 3×, "cat" 2×, rest once. // frequency("the") is 3; the single most-frequent count is also 3. 3 + 3 = 6. // // The driver is a `main` method on a `ref data Program` — the class-style program. That // method IS the entry point; the compiler constructs the program (`Program()`) and calls // `.main()`, so no separate launcher function is needed. ref data Program { func main() -> int { let counts = tally("the cat sat on the mat the cat ran") return frequency(counts, "the") + mostFrequentCount(counts) } } // ── ILEmitterTests__Bind_RefDataWithMethodsAndLambdas ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests.cs::Bind_RefDataWithMethodsAndLambdas topic: interop status: unverified // compiles cleanly (no auto-run claim was extracted) namespace T using "System.Net.Http" data Config(name: string, url: string) data Item(title: string, source: string) ref data Aggregator { configs: List items: List client: HttpClient init() { self.configs = List() self.items = List() self.client = HttpClient() } func start() { self.poll() } func poll() { var tasks = List, List)>>() for cfg in self.configs { let c = self.client let f = cfg tasks.Add(Task.Run(func() -> (List, List) { return (List(), List()) })) } } func query(filter: string, limit: int) -> List { var result = self.items if filter != "" { result = result.Where(func(n: Item) -> bool { return n.source == filter }).ToList() } return result.Take(limit > 0 ? limit : 50).ToList() } func count() -> int = self.items.Count func addConfig(name: string, url: string) = self.configs.Add(Config(name, url)) } // ── ILEmitterTests_ExternalReflection__Cast_ExplicitGenericArg_TypesElements ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_ExternalReflection.cs::Cast_ExplicitGenericArg_TypesElements topic: interop status: unverified // verified behavior: Test.go(...) == 30 namespace Test func go() -> int { let xs = List() xs.Add(10) xs.Add(20) var sum = 0 for n in xs.Cast() { sum += n } return sum } // ── ILEmitterTests_ExternalReflection__QualifiedExternalType_SilencesAmbiguity ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_ExternalReflection.cs::QualifiedExternalType_SilencesAmbiguity topic: interop status: unverified // verified behavior: reports diagnostic ES2151 namespace Test using "System.Threading" using "System.Timers" func go(t: System.Timers.Timer) -> double { return t.Interval } // ── ILEmitterTests_Interop__ChainedMember_JsonElement_GetArrayLength ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Interop.cs::ChainedMember_JsonElement_GetArrayLength topic: interop status: unverified // verified behavior: Test.run(...) == 3 namespace Test using "System.Text.Json" func run() -> int { let doc = JsonDocument.Parse("[10, 20, 30]") return doc.RootElement.GetArrayLength() } // ── ILEmitterTests_Interop__EnumLiteral_JsonValueKind_EmitsConstant ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Interop.cs::EnumLiteral_JsonValueKind_EmitsConstant topic: interop status: unverified // verified behavior: Test.run(...) == 1 namespace Test using "System.Text.Json" func run() -> int { let kind = JsonValueKind.Object return kind == JsonValueKind.Object ? 1 : 0 } // ── ILEmitterTests_Interop__ForIn_JsonEnumerateArray_GetProperty ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Interop.cs::ForIn_JsonEnumerateArray_GetProperty topic: interop status: unverified // verified behavior: Test.run(...) == "6" namespace Test using "System.Text.Json" func run() -> string { let doc = JsonDocument.Parse("[1, 2, 3]") let root = doc.RootElement var total = 0 for el in root.EnumerateArray() { total += el.GetInt32() } return total.ToString() } // ── ILEmitterTests_Interop__JsonDocument_ChainedMemberAccess ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Interop.cs::JsonDocument_ChainedMemberAccess topic: interop status: unverified // verified behavior: Test.run(...) == "object" namespace Test using "System.Text.Json" func run() -> string { let doc = JsonDocument.Parse("{}") return doc.RootElement.ValueKind == JsonValueKind.Object ? "object" : "other" } // ── ILEmitterTests_Interop__JsonDocument_Parse_RootElement_ValueKind_Stepped ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Interop.cs::JsonDocument_Parse_RootElement_ValueKind_Stepped topic: interop status: unverified // verified behavior: Test.run(...) == "object" namespace Test using "System.Text.Json" func run() -> string { let doc = JsonDocument.Parse("{}") let elem = doc.RootElement let kind = elem.ValueKind let isObj = kind == JsonValueKind.Object return isObj ? "object" : "other" } // ── ILEmitterTests_Interop__OptionalStructParam_DefaultInitialized ── // E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript). // provenance: ILEmitterTests_Interop.cs::OptionalStructParam_DefaultInitialized topic: interop status: unverified // verified behavior: Test.run(...) == "ok" namespace Test using "System.Text.Json" func run() -> string { let doc = JsonDocument.Parse("{}") return "ok" }