to count some of the children of note XXX. Now: XXX is not unique. I want to use the code in XXX’s parent’s action, but there might be another XXX somewhere else in the document. I also don’t know the absolute path of XXX. In other situations I can use
$Path/XXX
to refer to a specific child by name but sum_if doesn’t seem to understand that.
Any ideas?
My guess is that the argument to children cannot be a full Tinderbox expression, but only a literal string, and that furthermore, Tinderbox vars are fully evaluated to literal strings as part of the action-code evaluation. But @eastgate is the one to say for sure.
Not tested but this my be a situation where eval() is needed, i.e. something like sum_if(children(eval($Path + "/XXX")),$Attribute=="Value",1);. The logic here being that eval generates a string literal that works in offset reference to children.
Doesn’t seem to work in my tests. I wouldn’t expect it to, if my understanding is correct, since eval(...) is also a Tinderbox expression, so if children needs a literal string here eval won’t help matters.
@eastgate, given that I have the path of the note that I want in an attribute, is assigning that attribute to an intermediate var the only way to use that path in a designator? I.e.,
var path;
path = $Attribute;
sum(children(path), $Width)
things get tricky. When we evaluate the expression, to what is this bound? this is bound in sum(), sum_if(). find(), collect() and related constructs to the note that is being examined, not to the note that is performing the rule or action, so $Path is the path to that note, not the path to the action note!