interpolation — examples
← all topics · 66 examples · page 1 of 2 · raw source ↓
Runs `run` → "hi kae"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: FeatureMixingTests.cs::Axis4_EmbeddedMethodPromoted_SatisfiesProtocol topic: interpolation status: verified
// verified behavior: Test.run(...) == "hi kae"
namespace Test
data Greeter {
name: string
func describe() -> string {
return "hi {self.name}"
}
}
data Wrapped : IDescribable {
Greeter
tag: int
}
interface IDescribable {
func describe() -> string
}
func report(d: IDescribable) -> string = d.describe()
func run() -> string {
let w = Wrapped { name: "kae", tag: 1 }
return report(w)
}ILEmitterTests__Protocol_RefDataImpl_CalledViaProtocolParameter_DispatchesVirtually
interpolation runnable verifiedRuns `goCat` → "cat:black"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests.cs::Protocol_RefDataImpl_CalledViaProtocolParameter_DispatchesVirtually topic: interpolation status: verified
// verified behavior: Test.goCat(...) == "cat:black"
namespace Test
interface INamed {
func getName() -> string
}
ref data Dog : INamed {
breed: string
init(breed: string) {
self.breed = breed
}
}
func getName(self: Dog) -> string {
return "dog:{self.breed}"
}
ref data Cat : INamed {
color: string
init(color: string) {
self.color = color
}
}
func getName(self: Cat) -> string {
return "cat:{self.color}"
}
func describe(n: INamed) -> string {
return n.getName()
}
func goDog() -> string {
let d = Dog("lab")
return describe(d)
}
func goCat() -> string {
let c = Cat("black")
return describe(c)
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests.cs::StringInterpolation_IL_Runtime topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func greet(name: string) -> string {
return "hello {name}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests.cs::StringInterpolation_IntValue_IL_Runtime topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func format(x: int) -> string {
return "value: {x}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Adversarial.cs::Interp_ChainedMemberAccess topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
data Inner { v: int }
data Outer { inner: Inner }
func go() -> string {
let o = Outer { inner: Inner { v: 42 } }
return "got {o.inner.v}"
}ILEmitterTests_Coverage_Adversarial__Interp_EscapedBracesMixedWithHole
interpolation unknown verifiedCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Adversarial.cs::Interp_EscapedBracesMixedWithHole topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> string {
let n = 7
return "{{literal}} = {n}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Adversarial.cs::Interp_MethodCallInHole topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func square(n: int) -> int = n * n
func go() -> string = "sq={square(5)}"ILEmitterTests_Coverage_Adversarial__Interp_MultipleHolesAndOperators
interpolation unknown verifiedCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Adversarial.cs::Interp_MultipleHolesAndOperators topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> string {
let a = 3
let b = 4
return "{a}+{b}={a + b}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Adversarial.cs::Interp_ObjectLiteralInHole topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
data P { x: int, y: int }
func go() -> string = "p={P { x: 3, y: 4 }.x}"ILEmitterTests_Coverage_Adversarial__Interp_PropertyGetterHole_ValueTypeBoxes
interpolation unknown verifiedCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Adversarial.cs::Interp_PropertyGetterHole_ValueTypeBoxes topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> string {
let s = "hello"
return "len={s.Length}"
}ILEmitterTests_Coverage_Adversarial__Interp_TernaryWithNestedStringQuotes
interpolation unknown verifiedCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Adversarial.cs::Interp_TernaryWithNestedStringQuotes topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> string {
let n = 0 - 3
return "sign={n > 0 ? "+" : "-"}"
}Runs `go` → "sum=7"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Interp_ArithmeticExpression topic: interpolation status: verified
// verified behavior: Test.go(...) == "sum=7"
namespace Test
func go() -> string {
let a = 3
let b = 4
return "sum={a + b}"
}Runs `go` → "count=3"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Interp_IntegerBoxing topic: interpolation status: verified
// verified behavior: Test.go(...) == "count=3"
namespace Test
func go() -> string {
let n = 3
return "count={n}"
}Runs `go` → "{x}"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Interp_LiteralBraces topic: interpolation status: verified
// verified behavior: Test.go(...) == "{x}"
namespace Test
func go() -> string {
return "{{x}}"
}Runs `go` → "x=10"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Interp_MemberAccess topic: interpolation status: verified
// verified behavior: Test.go(...) == "x=10"
namespace Test
data Pt { x: int, y: int }
func go() -> string {
let p = Pt { x: 10, y: 20 }
return "x={p.x}"
}Runs `go` → "len=5"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Interp_MethodCall topic: interpolation status: verified
// verified behavior: Test.go(...) == "len=5"
namespace Test
func go() -> string {
let s = "hello"
return "len={s.Length}"
}Runs `go` → "a1b2"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Interp_MultipleHoles topic: interpolation status: verified
// verified behavior: Test.go(...) == "a1b2"
namespace Test
func go() -> string {
let x = 1
let y = 2
return "a{x}b{y}"
}Runs `go` → "hi alice"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Interp_SimpleVariable topic: interpolation status: verified
// verified behavior: Test.go(...) == "hi alice"
namespace Test
func go() -> string {
let name = "alice"
return "hi {name}"
}Runs `go` → "sign=+"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Interp_TernaryInsideHole topic: interpolation status: verified
// verified behavior: Test.go(...) == "sign=+"
namespace Test
func go() -> string {
let n = 5
return "sign={n > 0 ? "+" : "-"}"
}Runs `go` → "alice:30"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Tuple_MixedTypes topic: interpolation status: verified
// verified behavior: Test.go(...) == "alice:30"
namespace Test
func go() -> string {
let t = ("alice", 30)
return "{t.Item1}:{t.Item2}"
}Runs `go` → "n=42"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_ToStringInterpolation topic: interpolation status: verified
// verified behavior: Test.go(...) == "n=42"
namespace Test
func go() -> string {
let n = 42
return "n={n}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::Exe_MainProducesConsoleOutput topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func main() -> int {
let total = 7 * 6
Console.WriteLine("answer={total}")
return total
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::Reflection_FindsDeclaredMethod topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
using "System.Reflection"
pub ref data Widget {
id: int
init(id: int) { self.id = id }
pub func describe() -> string = "w{self.id}"
}
func go() -> bool {
let w = Widget(1)
let m = w.GetType().GetMethod("describe")
return m != nil
}Runs `go` → "w42"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::Reflection_InvokeMethodDynamically topic: interpolation status: verified
// verified behavior: Test.go(...) == "w42"
namespace Test
using "System.Reflection"
pub ref data Widget {
id: int
init(id: int) { self.id = id }
pub func describe() -> string = "w{self.id}"
}
func go() -> string {
let w = Widget(42)
let m = w.GetType().GetMethod("describe")
let result = m.Invoke(w, nil)
return result.ToString()
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::Added_CallInHole topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func dbl(x: int) -> int = x * 2
func go() -> string {
return "d={dbl(4)}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::Added_IndexInHole topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let xs = [9, 8]
return "first={xs[0]}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::Added_MemberChainHole topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
data P { x: int }
func go() -> string {
let p = P { x: 5 }
return "x={p.x}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::Added_PointerFieldHole topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
data B { n: int }
func go() -> string {
let b = new B { n: 7 }
return "n={b.n}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::AdditionOperator topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let a = 3
let b = 4
return "sum={a + b}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::AdjacentHoles topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let a = 3
let b = 4
return "{a}{b}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::AndOperatorInHole topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let a = true
let b = true
return "both={a && b}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::BclFormatPlaceholderStaysLiteral topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let x = 5
return "{0} and {x}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::BoolHole topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let f = true
return "flag={f}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::CallInHole topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func dbl(x: int) -> int = x * 2
func go() -> string {
return "dbl={dbl(5)}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::CallWithArgExpression topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func add(a: int, b: int) -> int = a + b
func go() -> string {
return "s={add(8, 12)}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::ChainedMemberInHole topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
data Inner { v: int }
data Outer { inner: Inner }
func go() -> string {
let o = Outer { inner: Inner { v: 7 } }
return "inner={o.inner.v}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::ComparisonOperator topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let a = 3
let b = 4
return "lt={a < b}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::DivisionOperator topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let a = 20
let b = 4
return "q={a / b}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::DoubleHole topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let d = 1.5
return "v={d}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::EmptyTextAroundSingleHole topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let x = 9
return "{x}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::HoleInLetThenReturn topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let n = 42
let s = "got {n}"
return s
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::IndexInHole topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let xs = [10, 20, 30]
return "first={xs[0]}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::LeadingAndTrailingText topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let x = 5
return "[{x}]"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::MemberChainInHole topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
data P { name: string }
func go() -> string {
let p = P { name: "kae" }
return "n={p.name}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::MixedValueAndRefHoles topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let name = "kae"
let age = 30
return "{name} is {age}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::ModuloInHole topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let a = 7
let b = 3
return "mod={a % b}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::MultiplicationOperator topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let a = 3
let b = 4
return "p={a * b}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::NegativeNumberHole topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let n = 0 - 7
return "neg={n}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::NestedArithmetic topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let a = 3
let b = 4
return "r={a + b + b + b - 1 + 4 - 2 - 1}"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::OrOperatorInHole topic: interpolation status: verified
// compiles cleanly (no auto-run claim was extracted)
func go() -> string {
let a = false
let b = true
return "any={a || b}"
}