up previous next
2.16.1 Tagging an Object
If E is any CoCoA object and S a string, then the function Tagged(E, S) returns the object E tagged with the string S . The returned object is then of type TAGGED(S) . The function tag returns S , the tag string of an object, and the function untagged returns E , the original object, stripped of its tag.

This is the way to add a new type at run-time.

Example
/**/  L := ["Dave", "March 14, 1959", 372];
/**/  M := Tagged(L, "MiscData");  -- L tagged with the string "MiscData"
/**/  type(L);  -- L is a list
LIST
/**/  type(M);  -- M is a tagged object
TAGGED("MiscData")
/**/  --M;  -- Until a special print function is defined, the printing of M
            -- is the same as L (with a WARNING)
--> WARNING: Cannot find "$BackwardCompatible.PrintTagged", so I'm implicitly untagging the value
--> ["Dave", "March 14, 1959", 372]
The next section explains how to define functions for pretty printing of tagged objects.