$lb ($listbuild) is instance of .... what?
I know that collection is instance of %AbstractList.
But what about $listbuild? Does it possible to detect that given variable is instance of $lb?
Comments
%SYS>w $listvalid($lb("test"))
1
%SYS>w $listvalid("test")
0
%SYS>w $listvalid("")
1$listbuild is not an object, so, it's not a check as an instance of, it is only possible that variable is valid as $listbuild
$listbuild as just a string with a special format, so, that's why this will also return true
%SYS>w $listvalid($char(1)) 1 %SYS>write $lb()=$c(1) 1
because
%SYS>zzdump $lb() 0000: 01 .
$listbuild() and all other functions, like $length(), $char() etc. are (I call them) basic functions of COS and have nothing to do with objects. The language of Cache (and of course IRIS ) handles data as raw (basic) data and not as objects, like some other (but not all) languages.
For example, in JavaScript you can do
var text="Some text";
alert("'" + text + "' has "+text.length + " characters");
alert("'Some text' has " + "Some text".length + " characters");because both, a (text)variable and a (text)string have an (object)property name 'length'.
Beside the raw data type COS also has object data type and most of the standard COS functions will accept an object property as argument, for example:
Class Test.Class Extends %RegisteredObject
{
Property Data as %String;
}
set text="Some text"
set obj = ##class(Test.Class).%New()
set obj.Data = "Some text";
write $length(text),!
write $length(obj.Data),!Although $list is just a string serialization format, it is conventional to declare such a string in a method parameter or return type as %List (i.e., %Library.List).
And Dmitriy pointed out, $listbuild creates not an instance, but a binary string of special format.
It's a datatype
You can even create your own datatype. Some libraries/frameworks like %ZEN or Ensemble have their own library of datatypes.