#strict

With activated #strict various old scripting inaccuracies will be ignored and proper type checking can be applied.

Declaration

The #strict directive has to be placed at the beginning of each script. #include or #appendto will follow the strictness of the script to be included or to which is to be appended.

Results

#strict 2

With activated #strict 2 various old scripting inaccuracies will be ignored and proper type checking can be applied.

Declaration

The #strict 2 directive has to be placed at the beginning of each script. With #include or #appendto the strictness of the script in which a function was defined is used.

Results

#strict 3

Any new script should be #strict 3. In this way further old scripting inaccuracies will be ignored, even stronger type checking can be applied and new language features are activated. Scripts without #strict 3 are accepted only for backwards compatibility reasons.

Declaration

The #strict 3 directive has to be placed at the beginning of each script. With #include or #appendto the strictness of the script in which a function was defined is used.

nil

#strict 3 introduces the new value nil. It represents undefined and unset values and is of type any. Furthermore, 0 and false are not implicitly converted to any anymore but keep their respective type. This makes it possible distinguish undefined values from 0 and false, for example for defining default parameter values that can be overriden by 0 or false. nil is unequal to any possible value of any other type, including 0 and false. Thus, it suffices to check x != nil to tell if a value has been defined. Anyway, !nil is true.
Because 0 and false are not any anymore, they can not be converted to other types like string, object, array or map which would trigger an error. Consequently, function arguments that should be passed as unset also have to be set to nil instead of 0.

The ? modifier

Likewise #strict 3 introduces a new modifier which allows "safe" navigation. ? is prepended to the navigation operators to obtain one of the following constructs: ?., ?[i], ?-> or ?->~. By using the ? modifier, those accesses do not trigger an error if the underlying value is nil. Instead, the whole expression is aborted and evaluates nil. Because by using this modifier the expression is assumed to return nil sometimes, the expression result is always dereferenced. This is due to the fact that using the result of a ?-modified expression in a reference context would defeat the purpose of the modifier, because in the case nil is returned it would error anyway.

Further Effects

Sven2, Juli 2001
Günther, Dezember 2007
Der Tod, Oktober 2019