Boolean Logic

The following set of functions all evaluate to true or false. They provide an alternate notation to using operators that may lend itself better when writing declarative code (e.g. when defining the fields of a declaration).

equals
switch
logic_and and logic_or
logic_not

equals

Syntax

equals?($left or @left, $right or @right)

Description

This function checks whether both arguments are equals, it is equivalent to doing left == right.

Arguments

Equals Arguments

Position

Possible Values

Required

Default Value

1

Resource collection

-OR-

Value

Yes

None

2

Resource collection

-OR-

Value

Yes

None

Result

true or false.

Examples

$a = 1 

$b = 2 

$c = 1 

equals?($a, $b) == false 

equals?($a, $c) == true 

switch

Syntax

switch($condition, @true_exp or $true_exp, @false_exp or $false_exp)

Description

This function evaluates the condition and returns either the true expression or false expression based on the value of $condition.

Arguments

Switch Arguments

Position

Possible Values

Required

Default Value

1

Value

Yes

None

2

Resource collection

-OR-

Value

Yes

None

3

Resource collection

-OR-

Value

Yes

None

Note:Both true expression and false expression should be of the same type.

Result

true expression or false expression

Examples

$anything_but_null = "foobar" 

$false_or_null = null

switch($anything_but_null, $var1, $var2) == $var1 

switch($false_or_null, @ec2, @google) == @google 

logic_and and logic_or

Syntax

logic_and($left, $right) and logic_or($left, $right)

Description

These functions apply the logical and or logical or operators respectively to their arguments. They are equivalent to $left && $right and $left || $right respectively.

Arguments

Logic_and and Logic_or Arguments

Position

Possible Values

Required

Default Value

1

Value

Yes

None

2

Value

Yes

None

Result

true or false.

Examples

$anything_but_null = "foobar" 

logic_and($anything_but_null, false) == false 

logic_and($anything_but_null, true) == true 

logic_and($anything_but_null, null) == false 

logic_and(null, null) == false 

 

logic_or($anything_but_null, false) == true 

logic_or($anything_but_null, true) == true 

logic_or($anything_but_null, null) == true 

logic_or(null, null) == false 

logic_not

Syntax

logic_not($value​)

Description

Applies the logical not operator.

Arguments

Logic_not Arguments

Position

Possible Values

Required

Default Value

1

Value

Yes

None

Result

true or false.

Examples

logic_not(true) == false 

logic_not(false) == true 

$any_value_but_null = "foobar" 

logic_not($any_value_but_null) == false 

logic_not(null) == true