Thanks again, Mark. After a lot of careful stepwise construction, this version works:
if !$IsPrototype {
$MyString=$Name;
$MyList=$Path(children);
$MyList.each(x){$Name(x)=$Name(x).replace("NN",$MyString)};$EdictDisabled=true;};
I’m really not sure what was wrong before, except that $IsPrototype had a lower case “i”. At any rate, I’ll briefly explain the purpose and why $EdictDisabled is effective. I want to create a note that is pre-populated with sub-notes that share its name. So I create a note, name it, e.g. “80”. Then I change its prototype to one that has sub-notes of the form “NNe”, “NNf”, and “NN”. These sub-notes are inherited and thus instantiated. The edict above is inherited at this point too. When it runs, it renames the sub-notes, then turns itself off. So the risk of the edict running too early is mitigated provided I name the parent note before I set its prototype.
Really, this exercise is an attempt to create what might be called an initializer or constructor method elsewhere. If there is a feature of Tinderbox that would be a better way to do this, in general, I’d be grateful to know.
Now, along the way I found some behavior I do not understand. Consider this note hierarchy:
100
NNa
NNb
NNc
Rule for 100:
$MyString=$Name;
$MyList=$Path(children);
$Text=$Text+$MyList.each(x){x};
Result in $Text:
eacheacheach
How could “each” possibly be the value of x?
So I thought to coerce x to a string, just to be sure.
$MyString=$Name; $MyList=$Path(children); $Text=$Text+$MyList.each(x){x+" "}
Result: eacheacheach
I thought I’d make the assignment within the loop in case there was some scope issue.
$MyString=$Name;
$MyList=$Path(children);
$MyList.each(x){$Text=x+" "};
eacheacheach
At this point I noticed that “eacheacheach” also contains the word ‘ache’…
While I do not understand why these versions did not do what I expected, I’m even more surprised that either x or the result of evaluating the .each loop could be the string “each”.