cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar

Make IsMissing work more intuitively

Pop quiz!

Question 1

Suppose you have a function GetCurrentValue which gets the current value of user certain interface objects, and returns missing (.) for others.  Suppose you have a list of interface objects (AllInterfaceObjects).

 

Will this work?

UserValues = Transform Each({object}, AllInterfaceObjects, GetCurrentValue(object));
FilteredValues = Filter Each({value}, UserValues, !Is Missing(value));

Answer:

View more...
Depends on what kind of values GetCurrentValue returns. 
Suppose GetCurrentValue returns (checkbox << Get Selected Indices()) for checkbox items.  If you apply IsMissing to the list of indices you do not get a boolean literal, you get a  list of booleans.
!IsMissing({1,2,3}) = {1,1,1}
Because a list of booleans is not True, Filter Each will remove it!  That means FilteredValue will not contain your list, even though your list was not missing.

Question 2

As you may or may not know, Create Database Connection is a function for creating database connections.  It returns a database connection on success, and missing on failure.

Does this work?

connection = Create Database Connection(magicString);
if( !Is Missing(connection), 
    RunSomeQuery(connection),
    Print("I have failed to connect")
);

Answer:

View more...
Nope.  Is Missing returns an error, complaining that it expects numeric values.

My Proposal

Make the use of missing (.) and Is Missing more disciplined. 

  • Do not magically thread the function through lists, tell me if the variable holding the list is missing or not.  
  • If Is Missing cannot handle your success, do not use missing to signal failure.