Skip to content

Commit

Permalink
Update operators section for structure addition
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchpaulus committed Mar 14, 2021
1 parent e529cab commit 4aa621c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ README.pdf
*.old
*.out

*.output.idf

doc/doc.md
doc/doc.pdf

Expand Down
12 changes: 12 additions & 0 deletions doc/code_samples/structure_addition_reference.nbem
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
original_struct = {
'key': 'value',
'second key': 10
}

updated_struct = original_struct + { 'other key': 'passed along', 'second key': 20 }

# This isn't a valid Version object, but go along with it.
Version,
<updated_struct.'key'>,
<updated_struct.'second key'>,
<updated_struct.'other key'>;
48 changes: 33 additions & 15 deletions doc/reference.inc.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,43 @@ others are there for consistency, but the usage should be rare.

## Operators

### Plus '`+`'
- Addition for numeric types
- String concatenation for string types
- `'Chiller ' + '1'`{.nbem} equals `'Chiller 1'`{.nbem}
- If using `'+'` operator with a string and a numeric, the
numeric is coerced to a string, and then the two strings are
concatenated. So `'Chiller ' + 1`{.nbem} (notice no quotes
around the number 1) becomes the string `'Chiller 1'` as you
would expect.
- List concatenation for list types
- `[1, 2, 3] + [4, 5]` equals `[1, 2, 3, 4, 5]`
- Structures - concatenate/update
- When two structures are used with the `+` operator, the keys from
both structures are combined into a new structure. If both
structures have the same key, then the value from the *second*
structure is used. This is how structures can be "updated" or
modified. An example is shown below.

```neobem
INCLUDE code_samples/structure_addition_reference.nbem
```

Compiling the above code results in:

```neobem
INCLUDE code_samples/structure_addition_reference.output.idf
```


### Other Algebraic Operators

The following operators are only valid for numeric types.

- Exponentiation: '`^`'
- Valid for numeric expressions only
- Plus '`+`'
- Addition for numeric types
- String concatenation for string types
- `'Chiller ' + '1'`{.nbem} equals `'Chiller 1'`{.nbem}
- If using `'+'` operator with a string and a numeric, the
numeric is coerced to a string, and then the two strings are
concatenated. So `'Chiller ' + 1`{.nbem} (notice no quotes
around the number 1) becomes the string `'Chiller 1'` as you
would expect.
- List concatenation for list types
- `[1, 2, 3] + [4, 5]` equals `[1, 2, 3, 4, 5]`
- Minus '`-`'
- Subtraction for numeric types
- Multiplication '`*`'
- Multiplication for numeric types
- Division '`/`'
- Division for numeric types


## Inline Data
Expand Down

0 comments on commit 4aa621c

Please sign in to comment.