routine or constant name search

8.12 Utilities

8.12.1 Routines iif

include std/utils.e
namespace utils
public function iif(atom test, object ifTrue, object ifFalse)

Used to embed an 'if' test inside an expression. iif stands for inline if or immediate if.

  1. test : an atom, the result of a boolean expression
  2. ifTrue : an object, returned if test is non-zero
  3. ifFalse : an object, returned if test is zero

An object. Either ifTrue or ifFalse is returned depending on the value of test.

Warning Note:
You must take care when using this function because just like all other Euphoria routines, this does not do any lazy evaluation. All parameter expressions are evaluated before the function is called, thus, it cannot be used when one of the parameters could fail to evaluate correctly. For example, this is an improper use of the iif statement:

first = iif(sequence(var), var[1], var)

The reason for this is that both var[1] and var will be evaluated. Therefore if var happens to be an atom, the var[1] statement will fail.
In situations like this, it is better to use the long style.

if sequence(var) then
     first = var[1]
     first = var
  end if
Example 1:
msg = sprintf("%s: %s", {
    iif(ErrType = 'E', "Fatal error", "Warning"), 
}) assign

include std/utils.e
namespace utils
public function assign(integer i1, object val1, integer i2 = 0, object val2 = 0,
        integer i3 = 0, object val3 = 0, integer i4 = 0, object val4 = 0,
        integer i5 = 0, object val5 = 0, integer i6 = 0, object val6 = 0,
        integer i7 = 0, object val7 = 0, integer i8 = 0, object val8 = 0,
        integer i9 = 0, object val9 = 0, integer i10 = 0, object val10 = 0)