Expressions

When you supply values for interpolations or directive parameters you can use variables or more complex expressions. For example, if x is the number 8 and y is 5, the value of (x + y)/2 resolves to the numerical value 6.5.

In interpolations, use ${expression} where expression gives the value you want to insert into the output as text. So ${(5 + 8)/2} prints “6.5”.

In directives, use <#directivename expession>, for example <#if expression>...</#if>.

Arithmetic expressions

Arithmetic expressions result in a number. RPL supports the standard arithmetic operations:

  • + — addition

  • - — subtraction

  • * — multiplication

  • / — division

  • % — modulus

Boolean expressions

Boolean expressions result in a value of either true or false. The constants true and false are the only two possible values.

You can use the following comparison operators:

  • == — equal

  • != — not equal

  • gt — is greater than

  • lt — is less then

  • le — is less than or equal to

  • ge — is greater than or equal to

You can also use the following logical operators:

  • && — boolean logical operation AND. This operation results in true if both its two operands are true, false otherwise.

  • || — boolean logical operation OR. This operation results in true if either one of its two operands is true, false when both operands are false.

To use the standard operators >, >=, < and <=, you must enclose them in parenthesis. This is because these operators can conflict with tag annotations. For example:

<#if (profile.age > 30 && profile.gender==‘F’)>

Date expressions

You cannot specify dates directly as constants. You must enter a date string then convert it to a date using the ?date ?datetime, or ?time built-ins. For an example, see the "Convert a string to a date" example in Using RPL instead of built-in functions.

Dates can be of type date, date-time, time, or unknown. Dates can be compared to other dates.

TIP: You can use the dayadd method to add or subtract days from the specified date. For more information, see dayadd in Method Reference.

Grouping expressions

You can use parentheses to group any expressions. Some examples:

                                   <#-- Output will be: -->
${3 * 2 + 2}                       <#-- 8 -->
${3 * (2 + 2)}                     <#-- 12 -->
${3 * ((2 + 2) * (1 / 2))}         <#-- 6 -->
${"green " + "mouse"?upper_case}   <#-- green MOUSE -->
${("green " + "mouse")?upper_case} <#-- GREEN MOUSE -->
<#if !( color = "red" || color = "green")>
  The color is nor red nor green
</#if>  

White space in expressions

RPL ignores superfluous white space in expressions. This means that the following are all equivalent:

${x + ":" + book.title?upper_case}  
${x+":"+book.title?upper_case}  
${
   x
 + ":"   +  book   .   title
   ?   upper_case
      }  

Next steps

Quick reference

Operator Precedence

Learn more

String operations

Specifying values directly

Working with variables