Skip to content

interpolation — examples

← all topics · 66 examples · page 2 of 2 · raw source ↓

ILEmitterTests_Interpolation__PlainVariable

interpolation unknown verified

Compiles

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

func go() -> string {
  let x = 5
  return "x={x}"
}

ILEmitterTests_Interpolation__StringHole

interpolation unknown verified

Compiles

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

func go() -> string {
  let who = "bob"
  return "hi {who}"
}

ILEmitterTests_Interpolation__SubtractionOperator

interpolation unknown verified

Compiles

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

func go() -> string {
  let a = 3
  let b = 4
  return "d={a - b}"
}

ILEmitterTests_Interpolation__TernaryInHole

interpolation unknown verified

Compiles

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

func go() -> string {
  let a = 3
  let b = 4
  return "max={a > b ? a : b}"
}

Compiles

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

func go() -> string {
  let a = 1
  let b = 2
  return "{a}+{b}={a + b}"
}

ILEmitterTests_Interpolation__TwoHoles

interpolation unknown verified

Compiles

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

func go() -> string {
  let a = 3
  let b = 4
  return "{a} and {b}"
}

Runs `go` → "hi kae"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PtrEmbedIface.cs::ValueEmbed_PromotedMethodThroughInterface   topic: interpolation   status: verified
// verified behavior: Test.go(...) == "hi kae"

data Greeter {
  name: string
  func describe() -> string { return "hi {self.name}" }
}

ILEmitterTests2__String_Interpolation_Field_Access

interpolation runnable verified

Runs `test` → "point 3,4"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::String_Interpolation_Field_Access   topic: interpolation   status: verified
// verified behavior: Test.test(...) == "point 3,4"

namespace Test

data P { x: int, y: int }

func test() -> string {
    let p = P { x: 3, y: 4 }
    return "point {p.x},{p.y}"
}

ILEmitterTests2__String_Interpolation_Single_Var

interpolation runnable verified

Runs `test` → "n is 42"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::String_Interpolation_Single_Var   topic: interpolation   status: verified
// verified behavior: Test.test(...) == "n is 42"

namespace Test

func test(n: int) -> string = "n is {n}"

ILEmitterTests2__String_Interpolation_Two_Variables

interpolation runnable verified

Runs `test` → "7:hello"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::String_Interpolation_Two_Variables   topic: interpolation   status: verified
// verified behavior: Test.test(...) == "7:hello"

namespace Test

func test(a: int, b: string) -> string = "{a}:{b}"

InterpolationBraceTests__HoleWithCall

interpolation runnable verified

Runs `go` → "squared=9"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: InterpolationBraceTests.cs::HoleWithCall   topic: interpolation   status: verified
// verified behavior: Test.go(...) == "squared=9"

namespace Test
func sq(n: int) -> int = n * n
func go() -> string {
    return "squared={sq(3)}"
}

Runs `go` → "3,4"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: InterpolationBraceTests.cs::InterpolationOnlyLocal_MemberAccessInHole   topic: interpolation   status: verified
// verified behavior: Test.go(...) == "3,4"

namespace Test
data P { x: int, y: int }
func go() -> string {
    let p = P { x: 3, y: 4 }
    return "{p.x},{p.y}"
}

Runs `go` → "{\"k\":9}"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: InterpolationBraceTests.cs::JsonObjectBraces_WithInterpolatedField   topic: interpolation   status: verified
// verified behavior: Test.go(...) == "{\"k\":9}"

namespace Test
using "System.Text"
func go() -> string {
    let key = "k"
    let val = 9
    let sb = StringBuilder()
    sb.Append("{")
    sb.Append("\"{key}\":{val}")
    sb.Append("}")
    return sb.ToString()
}

Compiles

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

namespace FnVar

func run() {
    let greet = func(name: string) -> string {
        return "hello {name}"
    }
    Console.WriteLine(greet("world"))
}

Compiles

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

namespace Greet

interface IGreeter {
    func greet(name: string) -> string
}

data Bot : IGreeter {
    prefix: string
}

func greet(b: Bot, name: string) -> string {
    return "{b.prefix} {name}"
}

TranspilerTests__Transpiles_StringInterpolation

interpolation unknown verified

Compiles

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

namespace Greet

pub func hello(name: string) -> string {
    return "hello {name}"
}