Empty Functions

Like other values, a function can be defined without initializing it. Or, put more correctly, a name can have an associated function type without having an associated value. The missing value for a function type is empty function, i.e. a function that returns the current missing value for the function's output type. The below example demonstrates the effect of calling an empty function.

    [#,$*4]<-#: f;    // Note, ''f()'' is an empty function.

    `print f(3);      // Emits warning: ''Call of empty function.''
                      // Output: [0, "", "", "", ""]
    %missing $ "aap";

    `print f(3);      // Emits warning: ''Call of empty function.''
                      // Output: [0, "aap", "aap", "aap", "aap"]
         

Like with the empty set, a function can explicitly be set to be empty. Though technically this is a different type of empty function because it has been initialized, the effect is the same. See the example below:

    # <- #: g <- {};    // Create a function with an empty body.
    %missing # -1;      // Set missing number to -1.
    `print g(3);        // Output: -1
         

Note that no warning is emitted (at level 3 or lower) because of the explicitness. The empty function body could also be seen as a special case of a function that does not assign to its out variable, and therefore returns the current missing value for its given output type.