# object

Definition: | object identifier -- or -- bool b = object(object x)
Description: | This serves to define the object type. You can also call it like an ordinary function to test if x is of type object. This will always be true for all legal values of x, be that integer, atom, string, or sequence, so object() will always return true (1), except when x is unassigned.
pwa/p2js: | Supported, however JavaScript is a typeless language, with "`object o`" being mapped to "`let /*object*/ o;`". An explicit hll/Phix "if object(x)" and similar expressions all work under pwa/p2js exactly as expected.
Comments: | All predefined and user-defined types can also be used as functions to test if a value is legal for that type. In previous versions of Phix, object(x) would crash when x was unassigned, but now yields false (0).
Example: |
    ? object({1,2,3})   -- always prints 1
Implementation: | There is a generic version of the object function implemented as :%opObj in builtins\VM\pType.e that the compiler only invokes as a last resort, preferring instead to inline that functionality if the argument is known to be assigned or the result variable, if any, is known to be an integer, ie does not require decref/dealloc. The compiler may also completely omit the test and/or any related code, if type inference/propagation determines that the result will always be true or always false. The file pwa/p2js.js defines object() with an optional name parameter, which if not "" triggers unassigned errors, but that (parameter) is not intended for or available from hll/Phix code, and only meant for use in manually hand-crafted replacements elsewhere in p2js.js, and in practice it ended up being invoked (that way) rather more sparingly than first predicted.
See Also: | atom, integer, sequence, string, Core Language