shelly-shell 0.5.4

A Rust based Unix style shell with a typed and structured language syntax.
# Hash maps

A hash maps keys to values. Entries have no guaranteed visit or display order.
Use `[:]` for an empty hash and `[key: value]` for entries.

<!-- example: HASH-LOOKUP -->
```shy
let $stock: [String: Integer] = ["tea": 8, "coffee": 5]
$stock["tea"] = $stock["tea"] - 2
echo $stock["tea"] $stock["missing"] $stock.count
```

```text
6 () 2
```


Missing keys read as `()`. Assignment inserts or replaces an entry. Unlike array
indexes, hash keys are values rather than positions. `"1"`, `1`, and `true`
remain different keys; equal numeric `1` and `1.0` share lookup identity.

## Key contracts and snapshots

`[String: Integer]` constrains both sides. As a value expression it constructs an
empty typed hash; `[(String): (Integer)]` stores Type objects instead.
`.key_type` and `.value_type` expose Type values for the collection contract.

Arrays, structs, and other supported values can be keys. The hash stores a key
snapshot, so changing the variable used to construct a key does not move the entry:

<!-- example: HASH-SNAPSHOT -->
```shy
let $coordinate = [2, 4]
let $markers = [$coordinate: "camp"]
$coordinate[0] = 9
echo $markers[[2, 4]] $markers[$coordinate]
```

```text
camp ()
```


Strings compare by text rather than their executable marker. Named keys retain
their distinct identity. Do not use a display String as a substitute for a key
of a nominal type.

## Iterate pairs

<!-- example: HASH-ITERATE -->
```shy
let $totals: [String: Integer] = ["east": 3, "west": 7]
let $sum = 0
for ($region, $count) in $totals { $sum = $sum + $count }
echo $sum
```

```text
10
```


Each step supplies a two-item array, which can be kept as one value or
destructured. A hash value of `()` remains data inside that pair. Iteration uses
a private snapshot; writes to the source do not change pending entries.
Use `.properties` to inspect the hash itself, rather than confusing its interface
with the entries it contains.

---

Related: [Arrays](Arrays) · [Iteration](Ranges-and-Iteration) · [Reflection](Reflection)