github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/docs/parser/addition.md (about)

     1  # `+` Addition Operator
     2  
     3  > Adds two numeric values together (expression)
     4  
     5  ## Description
     6  
     7  The Addition Operator adds two numeric values together in an expression. Those
     8  values are placed either side of the addition operator.
     9  
    10  
    11  
    12  ## Examples
    13  
    14  #### Expression
    15  
    16  ```
    17  » 3+2
    18  5
    19  ```
    20  
    21  #### Statement
    22  
    23  ```
    24  out (3+2)
    25  » 5
    26  ```
    27  
    28  ## Detail
    29  
    30  Unlike in some other programming languages, the `+` operator cannot be used to
    31  concatenate strings. This is because shells are historically untyped so you
    32  cannot always guarantee that numeric-looking value isn't a string. To solve
    33  this problem, by default Murex assumes anything that looks like a number is a
    34  number when performing addition. Thus overloading the `+` operator to
    35  concatenate strings would lead to a large class of bugs.
    36  
    37  ```
    38  » str = "3"
    39  » int = 2
    40  » $str + $int
    41  5
    42  ```
    43  
    44  For occasions when type safety is more important than the convenience of silent
    45  data casting, you can disable the above behaviour via `config`:
    46  
    47  ```
    48  » config set proc strict-types false
    49  » $str + $int
    50  Error in `expr` (0,1): cannot Add with string types
    51                      > Expression: $str + $int
    52                      >           : ^
    53                      > Character : 1
    54                      > Symbol    : Scalar
    55                      > Value     : '$str'
    56  ```
    57  
    58  ## See Also
    59  
    60  * [`*` Multiplication Operator](../parser/multiplication.md):
    61    Multiplies one numeric value with another (expression)
    62  * [`+=` Add With Operator](../parser/add-with.md):
    63    Adds the right hand value to a variable (expression)
    64  * [`-` Subtraction Operator](../parser/subtraction.md):
    65    Subtracts one numeric value from another (expression)
    66  * [`/` Division Operator](../parser/division.md):
    67    Divides one numeric value from another (expression)
    68  * [`cast`](../commands/cast.md):
    69    Alters the data type of the previous function without altering it's output
    70  * [`config`](../commands/config.md):
    71    Query or define Murex runtime settings
    72  * [`expr`](../commands/expr.md):
    73    Expressions: mathematical, string comparisons, logical operators
    74  * [`float` (floating point number)](../types/float.md):
    75    Floating point number (primitive)
    76  * [`int`](../types/int.md):
    77    Whole number (primitive)
    78  * [`num` (number)](../types/num.md):
    79    Floating point number (primitive)
    80  
    81  <hr/>
    82  
    83  This document was generated from [gen/expr/addition_op_doc.yaml](https://github.com/lmorg/murex/blob/master/gen/expr/addition_op_doc.yaml).