Skip to content

Operator

Mpl supports basic operators, +, -, *, / and len. These operartors when applied on types like, number, string, boolean behave like Python. These operator when applied to types unique to Mpl, the behavior not be obvious at first glance. Note that in case of Json type if the Json value is string or number, the same rule applies as their corresponding base type. Behavior of each operator is as following.

  1. + (add operator): Add operator adds 2 numbers or concatonates 2 strings. It can also be used to add time type with duration to move the. e.g.,

    x = duration (1 day)
    y = time ("10/17/2011 06:11 pm PDT")
    a = y + x
    a
    
    output is:

    10-18-2011 06:11:00 pm PDT
    

    in case of Json:

    s = json {"a": "cat", "b": "dog"}
    s.a + " & " + s.b
    

    output is:

    "cat & dog"
    
  2. - (minus operator): Minus operator substracts 2 numbers. - is not supported on string or boolean type. It can also be used to add or subract a time type with duration. e.g.,

    s = time "10/19/2011 06:11 am PDT"
    d = duration (24 hour)
    x = s -d
    x
    

    output is:

    10-18-2011 06:11:00 am PDT
    
  3. * (multiply operator): Multiply operator multiplies 2 numbers. * is not supported on string or time type. When duration type is multiplied by a number, the duration gets multiplied by the number.

    With duration:

    a = duration (1 day)
    a*2
    
    output is:

    48h:0m:0s
    
  4. / (divide operator): Divide operator divides 2 numbers. / is not supported on string or time type. When duration type is divided by a number, the duration is divided he number.

    With duration:

    a = duration (1 day)
    a/2
    
    output is:

    12h:0m:0s
    
  5. len (len operator): len operator is applicable to string and JSON type. For string it returns number of characters in a string. In case of Json it returns number of elements in JSON array or number of keys in case of JSON object. If the JSON val is string, it returns string length.

    mpl> x = "Apple"
    mpl> len x
    5
    

    With Json:

    mpl> x = json {"A":"dog", "B":[1, 5]}
    mpl> len x
    2
    mpl> len x.A
    3
    mpl> len x.B
    2