Objects (walax)
Soplang objects: string keys, property access, lookup, mutation, removal, copying, merging, and entries.
An object (walax) stores key-value pairs. Keys are strings, and values may
have any type. In an object literal, write a key as an identifier or a quoted
string.
Creating and Accessing Objects
walax qof = {magac: "Ayaan", da: 25} qor(qof.magac) // Ayaan qor(qof["da"]) // 25 door fure = "magaalo" qof[fure] = "Hargeysa" qor(qof.hel(fure)) // Hargeysa qor(qof.hel("shaqo", "ma jiro")) // ma jiro qor(qof.dherer()) // 3
Both dot notation and bracket notation support reads and writes.
hel(key, default?) uses the default only when the key is absent. A present
key storing maran still returns maran. Reading a missing key without a
default returns maran.
Shared Methods
| Method | Result |
|---|---|
dherer() | The number of keys; dherer(obj) is also valid |
leeyahay(key) | Check whether the key exists |
hel(key, default?) | Return the value or the supplied default |
dhig(key, value) | Set a value and return the original object |
saar(key) | Remove and return the value, or maran when the key is absent |
nadiifi() | Remove all keys and return the original object |
nuqul() | Return a shallow copy |
midee(other) | Return a new merged object |
door qof = {magac: "Ayaan", da: 25} qof.dhig("da", 26) qor(qof.saar("da")) // 26 qor(qof.leeyahay("da")) // been qor(qof.saar("maqan")) // maran
The earlier method tir(key) remains supported, but returns the object itself.
saar(key) returns the removed value instead.
Keys, Values, and Pairs
furayaal(), qiimayaal(), and lammaanayaal() all follow sorted-key order.
door qof = {magac: "Ayaan", da: 25} qor(qof.furayaal()) // [da, magac] qor(qof.qiimayaal()) // [25, Ayaan] qor(qof.lammaanayaal()) // [[da, 25], [magac, Ayaan]]
Merging and Copying
midee() leaves both inputs unchanged. When a key appears in both objects,
the right-hand object's value wins. The result is a shallow copy; nested
collections remain shared with the inputs.
door asal = {magac: "Ayaan", da: 25} door natiijo = asal.midee({da: 26, magaalo: "Hargeysa"}) qor(asal.da) // 25 qor(natiijo.da) // 26 qor(natiijo.magaalo) // Hargeysa
Objects do not have built-in hore() or dambe() methods. Those methods
apply to lists and strings. See the
reference.