Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
odino committed Feb 1, 2019
1 parent a41a313 commit caabc2c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
17 changes: 13 additions & 4 deletions docs/syntax/for.md
Expand Up @@ -56,12 +56,16 @@ echo(y) # 9
## In form

The "in" form of the `for` loops allows you to iterate over
an array:
an array or an hash:

``` bash
for x in [1, 2, 3] {
# x is 1, 2, 3
}

for x in {"a": 1, "b": 2, "c": 3} {
# x is 1, 2, 3
}
```
Both key and values are available in the loop:
Expand All @@ -71,6 +75,11 @@ for k, v in [1, 2, 3] {
# k is 0, 1, 2
# v is 1, 2, 3
}

for k, v in {"a": 1, "b": 2, "c": 3} {
# k is a, b, c
# v is 1, 2, 3
}
```
In terms of scoping, the "in" form follows the same rules
Expand All @@ -79,13 +88,13 @@ as the standard one, meaning that:
``` bash
k = "hello world"

for v in [1, 2, 3] {
for k, v in [1, 2, 3] {
# k is 0, 1, 2
# v is 1, 2, 3
}

echo(v) # "hello world"
echo(k) # v is not defined
echo(k) # "hello world"
echo(v) # v is not defined
```
## Next
Expand Down
18 changes: 14 additions & 4 deletions docs/types/hash.md
Expand Up @@ -12,7 +12,10 @@ Note that the `hash.key` hash property form is the preferred one, as it's more c

Accessing a key that does not exist returns null.

An individual hash element may be assigned to via its `hash["key"]` index or its property `hash.key`. This includes compound operators such as `+=`. Note that a new key may be created as well using `hash["newkey"]` or `hash.newkey`.
An individual hash element may be assigned to via its `hash["key"]`
index or its property `hash.key`. This includes compound operators
such as `+=`. Note that a new key may be created as well using `hash["newkey"]` or `hash.newkey`:

```bash
h = {"a": 1, "b": 2, "c": 3}
h # {a: 1, b: 2, c: 3}
Expand All @@ -37,7 +40,9 @@ h.y = 20
h # {a: 88, b: 2, c: 3, x: 10, y: 20}
```

It is also possible to extend a hash using the `+=` operator with another hash. Note that any existing keys on the left side will be replaced with the same key from the right side.
It is also possible to extend a hash using the `+=` operator
with another hash. Note that any existing keys on the left side
will be replaced with the same key from the right side:

```bash
h = {"a": 1, "b": 2, "c": 3}
Expand All @@ -48,7 +53,9 @@ h += {"c": 33, "d": 4, "e": 5}
h # {a: 1, b: 2, c: 33, d: 4, e: 5}
```

In a similar way, we can make a **shallow** copy of a hash using the `+` operator with an empty hash. Be careful, the empty hash must be on the left side of the `+` operator.
In a similar way, we can make a **shallow** copy of a hash using
the `+` operator with an empty hash. Be careful, the empty hash
must be on the left side of the `+` operator:

```bash
a = {"a": 1, "b": 2, "c": 3}
Expand All @@ -65,7 +72,10 @@ b # {a: 99, b: 2, c: 3}
a # {a: 1, b: 2, c: 3}
```

If the left side is a `hash["key"]` or `hash.key` and the right side is a hash, then the resulting hash will have a new nested hash at `hash.newkey`. This includes `hash["newkey"]` or `hash.newKey` as well.
If the left side is a `hash["key"]` or `hash.key` and the
right side is a hash, then the resulting hash will have a
new nested hash at `hash.newkey`. This includes `hash["newkey"]`
or `hash.newKey` as well:

```bash
h = {"a": 1, "b": 2, "c": 3}
Expand Down

0 comments on commit caabc2c

Please sign in to comment.