This commit is contained in:
commit
568474d52f
1591 files changed
+528213
No files matched your search
@@ -0,0 +1,36 @@
|
||||
# probe: a list in brackets assigned to a List variable, a struct field, a List element or a Dict entry: is it a List (append works), and do its items take the element type?
|
||||
@fieldwise_init
|
||||
struct Box(Copyable, Movable):
|
||||
var items: List[Int]
|
||||
var weights: List[Float64]
|
||||
|
||||
|
||||
def main() raises:
|
||||
var a = List[Int]()
|
||||
a = [1, 2]
|
||||
a.append(3)
|
||||
print(a)
|
||||
var f = List[Float64]()
|
||||
f = [1, 2]
|
||||
f.append(3)
|
||||
print(f)
|
||||
var b = Box(List[Int](), List[Float64]())
|
||||
b.items = [4, 5]
|
||||
b.items.append(6)
|
||||
b.weights = [7, 8]
|
||||
print(b.items, b.weights)
|
||||
var g: List[List[Int]] = [[1], [2]]
|
||||
g[0] = [9, 9]
|
||||
g[0].append(10)
|
||||
g.append([11])
|
||||
print(g)
|
||||
var d = Dict[String, List[Int]]()
|
||||
d["k"] = [1]
|
||||
d["k"].append(2)
|
||||
print(d["k"])
|
||||
var h: Dict[String, List[Float64]] = {"x": [1, 2]}
|
||||
h["x"].append(3)
|
||||
print(h["x"])
|
||||
var c = Box([1], [2])
|
||||
c.items.append(3)
|
||||
print(c.items, c.weights)
|
||||
Reference in new issue
Block a user