Skip to main content
Last updated

Operators

abs

Use abs to calculate the absolute value of a given number.

Basic syntax

To calculate the absolute value of a number, use the following syntax:

pact
(abs number)
pact
(abs number)

Arguments

Use the following argument to specify the number for which you want to calculate the absolute value using the abs Pact function.

ArgumentTypeDescription
numberdecimal or integerSpecifies the number for which to calculate the absolute value.

Return values

The abs function returns the absolute value of the number as a decimal or integer, depending on the input type.

Examples

The following example calculates the absolute value of a decimal number in the Pact REPL:

pact
pact> (abs (- 10.5 23.7))13.2
pact
pact> (abs (- 10.5 23.7))13.2

The following example calculates the absolute value of an integer:

pact
pact> (abs (- 10 23))13
pact
pact> (abs (- 10 23))13

add (+)

Use + to add numbers, concatenate strings and lists, or merge objects.

Basic syntax

To add numbers, concatenate strings and lists, or merge objects, use the following syntax:

pact
(+ oper1 oper2)
pact
(+ oper1 oper2)

Arguments

Use the following arguments to specify the values for addition, concatenation, or merging using the + Pact function.

ArgumentTypeDescription
oper1integer, decimal, string, [list], or objectSpecifies the first operand for addition, concatenation, or merging.
oper2integer, decimal, string, [list], or objectSpecifies the second operand for addition, concatenation, or merging.

Return value

The + function returns the result of addition for numbers, the concatenated string or list for strings and lists, or the resulting of merging for objects.

Examples

The following examples demonstrate how to use the + function to add two numbers in the Pact REPL:

pact
pact> (+ 1 2)3 pact> (+ 5.0 20.5)25.5
pact
pact> (+ 1 2)3 pact> (+ 5.0 20.5)25.5

The following examples demonstrate how to use the + function to concatenate strings and lists in the Pact REPL:

pact
pact> (+ "every" "body")"everybody" pact> (+ [1 2] [3 4])[1 2 3 4]
pact
pact> (+ "every" "body")"everybody" pact> (+ [1 2] [3 4])[1 2 3 4]

The following example demonstrates how to use the + function to merge objects in the Pact REPL:

pact
pact> (+ { "foo": 100 } { "foo": 1, "bar": 2 }){"bar": 2,"foo": 100}
pact
pact> (+ { "foo": 100 } { "foo": 1, "bar": 2 }){"bar": 2,"foo": 100}

In this example, merging the object fields using the + function results in the first operand value replacing the corresponding field in the second operand.

and?

Use and? to apply a logical AND operation to the results of applying a specified value to application functions func1 and func2, with short-circuit evaluation.

You can use any data type for the value argument as long as the two functions take that same data type and return the resulting boolean value for the logical AND operation performed by the and? function.

By convention, the data type is used if an argument represents a type-bound parameter like the value argument in this function:

(defun logicalAnd and?:bool (func1:( -> bool) func2:( -> bool) value:))

Basic syntax

To apply a logical AND operation to the results of applying a specified value to the functions func1 and func2, use the following syntax:

pact
(and? func1 func2 value)
pact
(and? func1 func2 value)

Arguments

Use the following arguments to specify the functions and value for the and? operation.

ArgumentTypeDescription
func1function x: -> boolSpecifies the first function to apply the specified value to. The result of applying the specified value of type <a> returns a boolean value.
func2function x: -> boolSpecifies the second function to apply the specified value to. The result of applying the specified value of type <a> returns a boolean value.
valueSpecifies the value to apply to both func1 and func2 functions.

Return values

The and? function returns a boolean value based on the result of applying value to func1 and func2 with the logical AND operation.

Examples

The following example demonstrates how to use the and? function in the Pact REPL:

pact
pact> (and? (> 20) (> 10) 15)false
pact
pact> (and? (> 20) (> 10) 15)false

In this example, the and? function applies the value 15 to the function (> 20), with the result being true because 20 > 15 is true. The function then applies the value of 15 to the (> 10) function, with the result being false because 10 > 15 is false. The result from the and? function, therefore, is false because the second condition is false.

and

Use and to perform a boolean logic AND operation with short-circuiting.

Basic syntax

To perform a boolean logic AND operation between two boolean values oper1 and oper2, use the following syntax:

pact
(and oper1 oper2)
pact
(and oper1 oper2)

Arguments

Use the following arguments to specify the boolean values for the and operation.

ArgumentTypeDescription
oper1boolSpecifies the first boolean value for the AND operation.
oper2boolSpecifies the second boolean value for the AND operation.

Return values

The and function returns a boolean value based on the result of the AND operation between the input boolean values.

Examples

The following example demonstrates how to use the and function to perform a boolean AND operation between the values true and false in the Pact REPL:

pact
pact> (and true false)false
pact
pact> (and true false)false

The following example illustrates using the and function to evaluate two expressions to determine whether an account string is valid:

pact
(and    (>= (length account) 3)    (<= (length account) 256))
pact
(and    (>= (length account) 3)    (<= (length account) 256))

In this example, both expressions must evaluate to true for an account string to be valid.

bitwise-and (&)

Use & to compute the bitwise AND operation between the first integer oper1 value and the second integer oper2 value.

Basic syntax

To compute the bitwise AND operation between oper1 and oper2, use the following syntax:

pact
(& oper1 oper2)
pact
(& oper1 oper2)

Arguments

Use the following arguments to specify the values for bitwise AND operation using the & Pact function.

ArgumentTypeDescription
oper1integerSpecifies the first operand.
oper2integerSpecifies the second operand.

Return value

The & function returns the result of the bitwise AND operation between oper1 and oper2.

Examples

The following examples demonstrate how to use the & function to perform bitwise AND manipulation of integer values in a Pact REPL:

pact
pact> (& 2 3)2 pact> (& 5 -7)1
pact
pact> (& 2 3)2 pact> (& 5 -7)1

bitwise-or (|)

Use | to compute the bitwise OR operation between the first integer oper1 value and the second integer oper2 value.

Basic syntax

To compute the bitwise OR operation between the oper1 and oper2 integer values, use the following syntax:

pact
(| oper1 oper2)
pact
(| oper1 oper2)

Arguments

Use the following arguments to specify the integers for the bitwise OR operation using the | Pact function.

ArgumentTypeDescription
oper1integerSpecifies the first integer for the OR operation.
oper2integerSpecifies the second integer for the OR operation.

Return value

The | function returns the result of the bitwise OR operation as an integer.

Examples

The following examples demonstrate how to use the | function to perform bitwise OR manipulation between two integers in a Pact REPL:

pact
pact> (| 2 3)3 pact> (| 5 -7)-3
pact
pact> (| 2 3)3 pact> (| 5 -7)-3

bitwise-reverse (~)

Use ~ to reverse all bits in the provided integer.

Basic syntax

To reverse all bits in an integer x, use the following syntax:

pact
(~ x)
pact
(~ x)

Arguments

Use the following argument to specify the integer for bit reversal using the ~ Pact function.

ArgumentTypeDescription
xintegerSpecifies the integer for which to reverse all bits.

Return value

The ~ function returns the result of reversing all bits in the provided integer.

Examples

The following example demonstrates how to use the ~ function to reverse all bits in the integer 15:

pact
pact> (~ 15)-16
pact
pact> (~ 15)-16

ceiling

Use ceiling to round up the value of a specified decimal value to the nearest integer or to a specified precision prec as a decimal.

Basic syntax

To round up the value of a decimal value to the nearest integer, use the following syntax:

pact
(ceiling value)
pact
(ceiling value)

To round up the value of a decimal value to a specified precision as a decimal, use the following syntax:

pact
(ceiling value precision)
pact
(ceiling value precision)

Arguments

Use the following arguments to specify the decimal value and optional precision for the ceiling Pact function.

ArgumentTypeDescription
valuedecimalSpecifies the decimal value to round up.
precisionintegerSpecifies the precision to round the specified value to (optional).

Return values

The ceiling function returns the rounded-up value as an integer or as a decimal based on the input and precision.

Examples

The following example rounds up a decimal value to the nearest integer in the Pact REPL:

pact
pact> (ceiling 3.5)4
pact
pact> (ceiling 3.5)4

The following example rounds up a decimal value to a precision of 2 decimal places:

pact
pact> (ceiling 100.15234 2)100.16
pact
pact> (ceiling 100.15234 2)100.16

In this example, ceiling rounds up the decimal value 100.15234 to a precision of 2 decimal places, resulting in 100.16.

dec

Use dec to convert a specified integer value to a decimal value. This function can be useful if you need to work with decimal values in Pact but have integer inputs.

Basic syntax

To convert a specified integer value to a decimal value, use the following syntax:

pact
(dec value)
pact
(dec value)

Arguments

Use the following argument to specify the integer for the dec Pact function.

ArgumentTypeDescription
valueintegerSpecifies the integer to cast to a decimal value.

Return values

The dec function returns the specified integer as a decimal value.

Example

The following example demonstrates how to use the dec function:

pact
pact> (dec 3)3.0
pact
pact> (dec 3)3.0

divide (/)

Use / to divide the first argument oper1 by the second argument oper2. Note that you can use this function to divide integer values or decimal values. However, you should use the same type for both oper1 and oper2 values.

Basic syntax

To divide oper1 by oper2, use the following syntax:

pact
(/ oper1 oper2)
pact
(/ oper1 oper2)

Arguments

Use the following arguments to specify the values for division using the / Pact function.

ArgumentTypeDescription
oper1integer or decimalSpecifies the value of the dividend.
oper2integer or decimalSpecifies the divisor.

Return value

The / function returns the result of dividing oper1 by oper2.

Examples

The following examples demonstrate how to use the / function to divide two values in a Pact REPL:

pact
pact> (/ 10.0 2.0)5.0 pact> (/ 8 3)2
pact
pact> (/ 10.0 2.0)5.0 pact> (/ 8 3)2

equal (=)

Use = to return true if the first argument oper1 is equal to the second argument oper2.

Basic syntax

To check if oper1 is equal to oper2, use the following syntax:

(= oper1 oper2)

Arguments

Use the following arguments to specify the values for comparison using the = Pact function.

ArgumentTypeDescription
oper1integer, decimal, string, time, bool, object, list, modref, guardSpecifies the first value for comparison.
oper2integer, decimal, string, time, bool, object, list, modref, guardSpecifies the second value for comparison.

Return value

The = function returns a boolean value indicating whether oper1 is equal to oper2.

Examples

The following example demonstrates how to use the = function to compare two integer values to check if the first value is equal to the second value:

pact
pact> (= 5 5)true
pact
pact> (= 5 5)true

The following example demonstrates how to use the = function to compare two decimal values to check if the first value is equal to the second value:

pact
pact> (= 3.14 2.71)false
pact
pact> (= 3.14 2.71)false

The following example demonstrates how to use the = function to compare two string values to check if the first string is equal to the second string:

pact
pact> (= "hello" "hello")true
pact
pact> (= "hello" "hello")true

The following example demonstrates how to use the = function to compare two time values to check if the first time is equal to the second time:

pact
pact> (= (time "2023-06-05T10:00:00Z") (time "2023-06-05T10:00:00Z"))true
pact
pact> (= (time "2023-06-05T10:00:00Z") (time "2023-06-05T10:00:00Z"))true

The following example demonstrates how to use the = function to compare two object values to check if the first object is equal to the second object:

pact
pact> (= { "name": "Alice", "age": 30 } { "name": "Alice", "age": 26 })false
pact
pact> (= { "name": "Alice", "age": 30 } { "name": "Alice", "age": 26 })false

The following example demonstrates how to use the = function to compare two list values to check if the first list is equal to the second list:

pact
pact> (= [1, 2, 3] [1, 2, 3])true
pact
pact> (= [1, 2, 3] [1, 2, 3])true

You can also the = function to evaluate variables and expressions. For example:

pact
(enforce (= amount 1.0) "Mint can only be 1")
pact
(enforce (= amount 1.0) "Mint can only be 1")

exp

Use exp to calculate the exponential function of the specified value.

Basic syntax

To calculate the exponential function of a value, use the following syntax:

(exp value)

Arguments

Use the following argument to specify the value for the exp Pact function:

ArgumentTypeDescription
valueinteger or decimalSpecifies the value for which to calculate the exponential function.

Return values

The exp function returns the exponential function of the specified value.

Examples

The following example demonstrates how to use the exp function to calculate the exponential value for three and round the result of this calculation to precision of six decimal places:

pact
pact> (round (exp 3) 6)20.085537
pact
pact> (round (exp 3) 6)20.085537

floor

Use floor to round down the value of a decimal value to an integer, or to a specified precision number of decimal places. The floor function is useful for situations where you need to round down decimal values in Pact contracts.

Basic syntax

To round down a decimal value to an integer, use the following syntax:

pact
(floor value)
pact
(floor value)

To round down a decimal value to a specified precision, use the following syntax:

pact
(floor value precision)
pact
(floor value precision)

Arguments

Use the following arguments to specify the decimal value and precision for the floor Pact function:

ArgumentTypeDescription
valuedecimalSpecifies the decimal value to round down.
precisionintegerSpecifies the precision to round down to for the resulting decimal value (optional).

Return values

The floor function returns the rounded-down value of the specified decimal:

  • If only value is provided, it returns an integer.
  • If precision is provided, it returns a decimal with the specified precision.

Examples

The following example demonstrates how to use the floor function to round down the 3.5 decimal value to the nearest integer:

pact
pact> (floor 3.5)3
pact
pact> (floor 3.5)3

The following example demonstrates how to use the floor function to round down the decimal value 100.15234 to a decimal value with a precision of two decimal places:

pact
pact> (floor 100.15234 2)100.15
pact
pact> (floor 100.15234 2)100.15

The following example uses the floor function in an expression for calculating a royalty payout:

pact
(royalty-payout:decimal  (floor (* sale-price royalty-rate) (fungible::precision)))
pact
(royalty-payout:decimal  (floor (* sale-price royalty-rate) (fungible::precision)))

greater-than-equal (>=)

Use >= to returns true if the first argument oper1 is greater than or equal to the second argument oper2.

Basic syntax

To check if oper1 is greater than or equal to oper2, use the following syntax:

pact
(>= oper1 oper2)
pact
(>= oper1 oper2)

Arguments

Use the following arguments to specify the values for comparison using the >= Pact function.

ArgumentTypeDescription
oper1integer, decimal, string, or timeSpecifies the first value for comparison.
oper2integer, decimal, string, or timeSpecifies the second value for comparison.

Return value

The >= function returns a boolean value indicating whether oper1 is greater than or equal to oper2.

Examples

The following example demonstrates how to use the >= function to compare two integer values to check if the first value (1) is greater than or equal to the second value (3):

pact
pact> (>= 1 3)false
pact
pact> (>= 1 3)false

The following example demonstrates how to use the >= function to compare two decimal values to check if the first value (5.24) is greater than or equal to the second value (2.52):

pact
pact> (>= 5.24 2.52)true
pact
pact> (>= 5.24 2.52)true

The following example demonstrates how to use the >= function to compare two string values to check if the first value (abc) is greater than or equal to the second value (def):

pact
pact> (>= "abc" "def")false
pact
pact> (>= "abc" "def")false

greater-than (>)

Use > to return true if the first argument oper1 is greater than the second argument oper2.

Basic syntax

To check if oper1 is greater than oper2, use the following syntax:

pact
(> oper1 oper2)
pact
(> oper1 oper2)

Arguments

Use the following arguments to specify the values for comparison using the > Pact function.

ArgumentTypeDescription
oper1integer, decimal, string, or timeSpecifies the first value for comparison.
oper2integer, decimal, string, timeSpecifies the second value for comparison.

Return value

The > function returns a boolean value indicating whether oper1 is greater than oper2.

Examples

The following example demonstrate how to use the > function to compare two integer values to check if the first value (1) is greater than the second value (3):

pact
pact> (> 1 3)false
pact
pact> (> 1 3)false

The following example demonstrates how to use the > function to compare two decimal values to check if the first value (5.24) is greater than the second value (2.52):

pact
pact> (> 5.24 2.52)true
pact
pact> (> 5.24 2.52)true

The following example demonstrates how to use the > function to compare two string values to check if the first value (abc) is greater than the second value (def):

pact
pact> (> "abc" "def")false
pact
pact> (> "abc" "def")false

less-than-equal (<=)

Use <= to return true if the first oper1 argument is less than or equal to the second oper2 argument.

Basic syntax

To check if oper1 is less than or equal to oper2, use the following syntax:

pact
(<= oper1 oper2)
pact
(<= oper1 oper2)

Arguments

Use the following arguments to specify the values for comparison using the <= Pact function.

ArgumentTypeDescription
oper1<a[integer,decimal,string,time]>Specifies the first value for comparison.
oper2<a[integer,decimal,string,time]>Specifies the second value for comparison.

Return value

The <= function returns a boolean value indicating whether oper1 is less than or equal to oper2.

Examples

The following example demonstrates how to use the <= function to compare two integer values to check if the first value (1) is less than or equal to the second value (3):

pact
pact> (<= 1 3)true
pact
pact> (<= 1 3)true

The following example demonstrates how to use the >= function to compare two decimal values to check if the first value (5.24) is less than or equal to the second value (2.52):

pact
pact> (<= 5.24 2.52)false
pact
pact> (<= 5.24 2.52)false

The following example demonstrates how to use the >= function to compare two string values to check if the first value (abc) is less than or equal to the second value (def):

pact
pact> (<= "abc" "def")true
pact
pact> (<= "abc" "def")true

ln

Use ln to compute the natural logarithm of a specified value.

Basic syntax

To compute the natural logarithm of a value, use the following syntax:

pact
(ln value)
pact
(ln value)

Argument

Use the following argument to specify the value for which you want to compute the natural logarithm using the ln Pact function.

ArgumentTypeDescription
valueinteger or decimalSpecifies the value for which you want to compute the natural logarithm.

Return value

The ln function returns the natural logarithm of the specified value.

Examples

The following example demonstrates how to use the ln function to computer the natural logarithm for the value of 60 and round the result to 6 decimal places:

pact
pact> (round (ln 60) 6)4.094345
pact
pact> (round (ln 60) 6)4.094345

log

Use log to compute the logarithm of the speified value with the specified base.

Basic syntax

To compute the logarithm of a specified value with the specified base, use the following syntax:

pact
(log base value)
pact
(log base value)

Arguments

Use the following arguments to specify the base and value for which you want to compute the logarithm using the log Pact function.

ArgumentTypeDescription
baseinteger or decimalSpecifies the base of the logarithm.
valueinteger or decimalSpecifies the value for which you want to compute the logarithm.

Return value

The log function returns the logarithm of value with base base.

Examples

The following example demonstrates how to use the log function to computer the logarithm of 256 with base 2:

pact
pact> (log 2 256)8
pact
pact> (log 2 256)8

less-than (<)

Use < to return true if the first oper1 argument is less than the second oper2 argument.

Basic syntax

To check if oper1 is less than oper2, use the following syntax:

pact
(< oper1 oper2)
pact
(< oper1 oper2)

Arguments

Use the following arguments to specify the values for comparison using the < Pact function.

ArgumentTypeDescription
oper1integer, decimal, string, or timeSpecifies the first value for comparison.
oper2integer, decimal, string, timeSpecifies the second value for comparison.

Return value

The < function returns a boolean value indicating whether oper1 is less than oper2.

Examples

The following example demonstrates how to use the < function to compare two integer values to check if the first value (1) is less than the second value (3)::

pact
pact> (< 1 3)true
pact
pact> (< 1 3)true

The following example demonstrates how to use the < function to compare two decimal values to check if the first value (5.24) is less than the second value (2.52):

pact
pact> (< 5.24 2.52)false
pact
pact> (< 5.24 2.52)false

The following example demonstrates how to use the < function to compare two string values to check if the first value (abc) is less than the second value (def):

pact
pact> (< "abc" "def")true
pact
pact> (< "abc" "def")true

mod

Use mod to compute the remainder of oper1 divided by oper2.

Basic syntax

To compute the remainder of oper1 divided by oper2, use the following syntax:

(mod oper1 oper2)

Arguments

Use the following arguments to specify the integers for which you want to compute the remainder using the mod Pact function.

ArgumentTypeDescription
oper1integerSpecifies the dividend.
oper2integerSpecifies the divisor.

Return value

The mod function returns the remainder of the division of oper1 by oper2.

Examples

The following example demonstrates how to use the mod function to compute the remainder when 13 is divided by 8:

pact
pact>(mod 13 8)5
pact
pact>(mod 13 8)5

multiply (*)

Use * to multiply the first oper1 argument by the second oper12 argument. Note that you can use this function to multiply integer values or decimal values. However, you should use the same type for both oper1 and oper2 values.

Basic syntax

To multiply oper1 by oper2, use the following syntax:

pact
(* oper1 oper2)
pact
(* oper1 oper2)

Arguments

Use the following arguments to specify the values for multiplication using the * Pact function.

ArgumentTypeDescription
oper1integer or decimalSpecifies the first multiplier.
oper2integer or decimalSpecifies the second multiplier.

Return value

The * function returns the result of multiplying oper1 by oper2.

Examples

The following example demonstrates how to use the * function to multiply two decimal values:

pact
pact> (* 0.5 10.0)5.0
pact
pact> (* 0.5 10.0)5.0

The following example demonstrates how to use the * function to multiply two integer values:

pact
pact> (* 3 5)15
pact
pact> (* 3 5)15

These examples illustrate how to use the * function to perform multiplication operations in Pact, facilitating arithmetic calculations with both integer and decimal values.

not-equal (!=)

Use != to return true if the first oper1 argument does not equal the second oper2 argument. This function allows you to write conditional logic based on whether two values are not equal.

Basic syntax

To check if oper1 does not equal oper2, use the following syntax:

pact
(!= oper1 oper2)
pact
(!= oper1 oper2)

Arguments

Use the following arguments to specify the values for comparison using the != Pact function.

ArgumentTypeDescription
oper1integer, string, time, decimal, bool, list, object, keyset, guard, or moduleSpecifies the first value for comparison.
oper2integer, string, time, decimal, bool, list, object, keyset, guard, or moduleSpecifies the second value for comparison.

Return value

The != function returns true if oper1 does not equal oper2, otherwise false.

Examples

The following example demonstrates how to use the != function to check whether two strings are not equal:

pact
pact> (!= "hello" "goodbye")true
pact
pact> (!= "hello" "goodbye")true

In the following example, the != function ensures that the sender and receiver accounts are not equal to prevent the sender initiating a transfer from also being the receiver of the transfer:

pact
(enforce (!= sender receiver) "sender cannot be the receiver of a transfer")
pact
(enforce (!= sender receiver) "sender cannot be the receiver of a transfer")

not?

Use not? to apply a logical NOT operation to the results of applying a specified value to an application function.

You can use any data type for the value argument as long as the app function takes that same data type and returns the resulting boolean value for the logical NOT operation performed by the not? function.

By convention, the data type is used if an argument represents a type-bound parameter like the value argument in this function:

Basic syntax

To apply a logical NOT operation to the results of applying a specified value to an application function app, use the following syntax:

pact
(not? app value)
pact
(not? app value)

Arguments

Use the following arguments to specify the application function and the value to be applied using the not? Pact function.

ArgumentTypeDescription
appfunction x: -> boolSpecifies the application function to apply the specified value to. The result of applying the specified value returns a boolean value.
valueSpecifies the value to be applied to the application function.

Return value

The not? function returns a boolean value representing the logical negation of the result of applying the value to the application function.

Examples

The following example demonstrates how to use the not? function in the Pact REPL:

pact
pact> (not? (> 20) 15)false
pact
pact> (not? (> 20) 15)false

In this example, the application function is (> 20) and the value is 15. Because the expression 20 > 15 evaluates to true, and not? negates this value, the not? function returns false.

not

Use not to compute the boolean negation of a specified value.

Basic syntax

To compute the boolean negation of the specified value, use the following syntax:

pact
(not value)
pact
(not value)

Argument

Use the following argument to specify the boolean value for which you want to compute the negation using the not Pact function.

ArgumentTypeDescription
valueboolSpecifies the expression to evaluate that returns the boolean value to be negated.

Return value

The not function returns the boolean negation of the input value.

Examples

The following example demonstrates how to use of the not function in the Pact REPL:

pact
pact> (not (> 1 2))true
pact
pact> (not (> 1 2))true

In this example, the expression (> 1 2) evaluates to false, and the not function negates this value, resulting in true.

or?

Use or? to apply a logical OR operation to the results of applying a specified value to application functions func1 and func2, with short-circuit evaluation.

You can use any data type for the value argument as long as the two functions take that same data type and return the resulting boolean value for the logical OR operation performed by the or? function.

By convention, the data type is used if an argument represents a type-bound parameter like the value argument in this function.

Basic syntax

To apply a logical OR operation to the results of applying a value to two application functions, use the following syntax:

pact
(or? func1 func2 value)
pact
(or? func1 func2 value)

Arguments

Use the following arguments to specify the functions and the value to be applied using the or? Pact function.

ArgumentTypeDescription
func1function x: -> boolSpecifies the first function to apply the specified value to. The result of applying the specified value returns a boolean value.
func2function x: -> boolSpecifies the second function to apply the specified value to. The result of applying the specified value returns a boolean value.
valueSpecifies the value to apply to both func1 and func2 functions.

Return value

The or? function returns a boolean value representing the logical OR operation after evaluating the results from applying the specified value to the two application functions.

Examples

The following example demonstrates how to use the or? function in the Pact REPL:

pact
pact> (or? (> 20) (> 10) 15)true
pact
pact> (or? (> 20) (> 10) 15)true

In this example, the or? function applies the value 15 to the function (> 20), with the result being true because 20 > 15 is true. Because the function performs short-circuit evaluation on the results, the or? function returns true because the first condition is true.

or

Use or to apply a logical OR operation with short-circuit evaluation.

Basic syntax

To perform a logical OR operation with short-circuit evaluation, use the following syntax:

pact
(or oper1 oper2)
pact
(or oper1 oper2)

Arguments

Use the following arguments to specify the boolean values for which you want to perform the logical OR operation using the or Pact function.

ArgumentTypeDescription
oper1boolSpecifies the first expression to evaluate that returns the boolean value to perform the logical OR operation on.
oper2boolSpecifies the second expression to evaluate that returns the boolean value to perform the logical OR operation on.

Return value

The or function returns a boolean value based on the logical OR operation of the input values.

Examples

The following example demonstrates how to use the or function in the Pact REPL:

pact
pact> (or (> 20 10) (> 10 15))true
pact
pact> (or (> 20 10) (> 10 15))true

In this example, the or function evaluates the expressions (> 20 10) and (> 10 15). The boolean value returns for the first expression is true because 20 > 15 is true. Because the or function performs short-circuit evaluation on the results, the function returns true because the first expression is true.

power-of (^)

Use ^ to raises the oper1 argument to the power of the oper2 argument.

Basic syntax

To raise oper1 to the power of oper2, use the following syntax:

pact
(^ oper1 oper2)
pact
(^ oper1 oper2)

Arguments

Use the following arguments to specify the base and exponent for raising to a power using the ^ Pact function.

ArgumentTypeDescription
oper1integer or decimalSpecifies the base value.
oper2integer or decimalSpecifies the exponent value.

Return value

The ^ function returns the result of raising oper1 to the power of oper2.

Examples

The following example demonstrates how to use the ^ function to raise 2 to the power of 3 in a Pact REPL:

pact
pact> (^ 2 3)8
pact
pact> (^ 2 3)8

shift

Use shift to perform a bitwise shift operation on the integer oper1 by oper2 bits. If oper2 is positive, this function shifts oper1 to the left. If oper2 is negative, the function shifts oper1 to the right. Right shifts perform sign extension on signed number types, filling the top bits with 1 if oper1 is negative and with 0 otherwise.

Basic syntax

To shift the integer oper1 by oper2 bits, use the following syntax:

pact
(shift oper1 oper2)
pact
(shift oper1 oper2)

Arguments

Use the following arguments to specify the integer values to be shifted using the shift Pact function.

ArgumentTypeDescription
oper1integerSpecifies the integer value to be shifted.
oper2integerSpecifies the number of bits to shift oper1 by.

Return value

The shift function returns the result of shifting oper1 by oper2 bits.

Examples

The following example demonstrates how to use the shift function to shift the integer 255 to the left by 8 bits:

pact
(shift 255 8)65280
pact
(shift 255 8)65280

The following example demonstrates how to use the shift function to shift the integer 255 to the right by 1 bit:

pact
(shift 255 -1)127
pact
(shift 255 -1)127

The following example demonstrates how to use the shift function to shift the negative integer -255 to the left by 8 bits:

pact
(shift -255 8)-65280
pact
(shift -255 8)-65280

The following example demonstrates how to use the shift function to shift the negative integer -255 to the right by 1 bit:

pact
(shift -255 -1)-128
pact
(shift -255 -1)-128

These examples illustrate how to use the shift function to perform bitwise shift operations on integers in Pact, either to the left or to the right, with sign extension for right shifts on signed numbers.

sqrt

Use sqrt to compute the square root of the given value.

Basic syntax

To calculate the square root of a value, use the following syntax:

pact
(sqrt value)
pact
(sqrt value)

Arguments

Use the following argument to specify the value for which to compute the square root using the sqrt Pact function.

ArgumentTypeDescription
valueinteger or decimalSpecifies the value that you want to compute the square root for.

Return value

The sqrt function returns the square root of the specified value. The return type depends on the type of the input value and whether the square root for the input value is a whole number.

Examples

The following example demonstrates how to use the sqrt function to calculate the square root of the integer value 25 that returns an integer value:

pact
pact> (sqrt 25)5
pact
pact> (sqrt 25)5

The following example calculates the square root of the decimal value 144.0 that returns a decimal value:

pact
(sqrt 144.0)12.0
pact
(sqrt 144.0)12.0

The following example calculates the square root for 48 and rounds the result to four decimal places:

pact
(round (sqrt 48) 4)6.9282
pact
(round (sqrt 48) 4)6.9282

This example illustrates how to use the sqrt function to compute the square root of a value in Pact, producing either an integer or a decimal result.

subtract (-)

Use - to negate a value or to subtract oper2 from oper1.

Basic syntax

To negate value, use the following syntax:

pact
(- value)
pact
(- value)

To subtract oper2 from oper1, use the following syntax:

pact
(- oper1 oper2)
pact
(- oper1 oper2)

Arguments

Use the following arguments to specify the values for negation or subtraction using the - Pact function.

ArgumentTypeDescription
valueinteger or decimalSpecifies the value to be negated.
oper1integer or decimalSpecifies the value to be subtracted from.
oper2integer or decimalSpecifies the value to subtract from oper1.

Return value

The - function returns the negation of the specified value, or the result of subtracting oper2 from oper1.

Examples

The following example demonstrates how to use the - function to negate a value in a Pact REPL:

pact
pact> (- 1.0)-1.0
pact
pact> (- 1.0)-1.0

The following example demonstrates how to use the - function to subtract integer values in a Pact REPL:

pact
pact> (- 3 2)1
pact
pact> (- 3 2)1

xor

Use xor to compute the bitwise exclusive OR (xor) operation between two integer arguments.

Basic syntax

To compute the bitwise XOR operation between two integers, use the following syntax:

pact
(xor oper1 oper2)
pact
(xor oper1 oper2)

Arguments

Use the following arguments to specify the integers for the bitwise XOR operation using the xor Pact function.

ArgumentTypeDescription
oper1integerSpecifies the first integer for the XOR operation.
oper2integerSpecifies the second integer for the XOR operation.

Return value

The xor function returns the result of the bitwise XOR operation as an integer.

Examples

The following examples demonstrate how to use the xor function to compute the bitwise XOR operation between two integers:

pact
(xor 127 64)63 (xor 5 -7)-4
pact
(xor 127 64)63 (xor 5 -7)-4