Z# (Zee-sharp)

A new .NET language

Map

A key-value map.

capacity = 42
m = Map<Str, U8>(capacity)

m["key1"] = 1
m["key2"] = 2
m["key3"] = 42

// how do these indexers work on objects?
indexer: <K, V>(self: Map<K, V>, key: K, val: V)
    ...

Map Initializers

TBD what would be the syntax to declaratively define a map?

map := ["key1" = 1, "key2" = 2, "key3" = 42]
map := {
    "key1" = 1
    "key2" = 2
    "key3" = 42
}

TBD

Support mapping a map to and from a structure.

s := Struct
    fld1 = 42
    fld2 = "42"

// untyped map to allow any value type?
m: Map <= s
m: Map<Str, Any> <= s   // or explicitly typed
// 'fld1' = 42
// 'fld2' = '42'

// map back to structure
x: Struct <= m

// TBD: throw errors when missing members?
// how to opt-in/out?
x: Struct <=! m     // throw errors
x: Struct <=? m     // don't throw errors

Allow maps to be passed as parameters to any function.

fn: (p1: U8, p2: Str)
    ...

// use tuple syntax to create maps?
// How is this not a struct?
m := {p1 = 42, p2 = "42"}
// special syntax?
m := {p1 <= 42, p2 <= "42"}
m := {p1 .= 42, p2 .= "42"}     // for structs specifically?
fn(m)

fn2: (p1: U8, p2: Str, p3: U16?)
    ...

// ok, optional p3 is not specified (Nothing)
fn2(m)

Keys MUST match field (struct) or parameter (function) names! (cannot fully check at compile time) Throw errors or not?


Allow map syntax to be equal to object syntax - as a dynamic object.

// use array/list syntax to create maps? (associative arrays)
m := (a = 42, b = "42")
// or object syntax?
m := {p1 = 42, p2 = "42"}
// or special object syntax?
m := {p1 <= 42, p2 <= "42"}  // '<=' is reserved for mapping!
m := {p1 = 42; p2 = "42"}    // different separator?

// what is the syntax for accessing dynamic properties?
x := m.a
m.a = 101
// creates a new entry in the map
m.x := x     // 'x'=<value of x>

For .NET interop we could use Dictionary<TKey, TValue> and not use a Map type at all.