CTM, TMQL: Let's define 'undef'
Here I would like to elaborate a bit on the background why null and undef are two different things and why I think that undef should not only be in TMQL, but actually also in CTM.
Let us consider a simple query:
$p isa Person
Here the TMQL processor is instructed to find all instances of Person, bind these one by one to the variable $p and then find for each person all its homepage occurrences.
If a person had exactly one homepage URL, then we would see that in the result list. If he had two, we would see both. If he had none, we would see nothing. But that may be exactly what we wanted in the first place.
If we would like to record the person's name as well, we can extend the query to:
$p isa Person
Again, the same mechanism of grouping is used: for every instance of Person the expression
is evaluated. If we for the moment assume that every person has exactly one name, then for persons with exactly one homepage we will also see exactly one result tuple, say:
If Mr. Howard had two homepages, then we would get
"The Lying Rodent", "http://www.tampa-incident.gov.au/"
But if the most honorable ex prime minister had not a single homepage, the list would be empty, and we would see no trace of him.
Maybe a Howard-free result is what we wanted. But maybe we would like to record this very fact differently:
- "If there are homepages, then show them. But if the list is empty, then use something to indicated that there is, uhm, something."
This is where undef steps in. It can represent the "something is there, but I cannot say what it is" part:
Above I used it together with the || operator. That takes care of the "if there is something, use that. If not, use the expression on the right" part.
With no J.H. homepages we would then expect:
In Perl undef would be modelled as undef (what a coincidence!), in Python it is None, C++ has NULL and in Jaaaaaavaaaaaa it would be null, or so.
Of course, you could also use a particular string as in
but then everyone who gets the results must know how to recognize this very string. undef is a standardized way to flag undefinedness.
undef is not null
TMQL also has a special constant null.
That is a synonym for () and basically means nothing there. And Nothing there is not the same as something there.
Suppose we need to write a topic map about persons and would record their homepages there.
What would you do to record "there is a homepage, I am sure, but I do not (yet) know what it is"? The known unknowns, so to say.
CTM does not yet allow to write
But maybe it should:
- You cannot leave the occurrence value blank (or can you?), and
- if you omit the homepage occurrence altogether, that would not reflect your intentions. And a TMCL validator enforcing at least one homepage occurrence would complain.
Work supported by the Austrian Research Centers.