String evaluation in stamp

Hello,

I read that I can edit the attribute $DisplayExpression

and give it the value

$Name+": "+ $ChildCount;

This will generate the expected string “some title: some number"

However if I add

$DisplayExpression=$Name+": "+ $ChildCount;

to a stamp and apply it, I only get the string

“some number” or sometimes part of the $name - I tried escaping it “:” to no avail.

Still if I change the stamp to:

$DisplayExpression=$Name+”-"+ $ChildCount;

Then all is well.

Could someone please point me to some doc that explains this behavior/impact of “:” and/or the mistake I am making?

Regards,

Philippe

When $DisplayExpression is set by assigning a value to the attribute, such as in a stamp, needs to have the right side enclosed in parentheses:

$DisplayExpression="$Name + ': ' + $ChildCount";

Not enclosing the right side of the action code in the stamp is a common error – we’ve all made that mistake. The right hand side of the action code is the expression that you want to store in $DisplayExpression, which is why it is enclosed in parentheses. The code you wrote is telling Tinderbox to evaluate the terms on the right side, and then store the result of that evaluation in $DisplayExpression, which is why you end up with the content of $DisplayExpression as a string instead of an expression.

See more here.

1 Like

@PaulWalters - Many thanks.
Regards,
Philippe

This is literally true.

The problem here — and this is both complicated and one of the most profound beauties of computer science — is that $DisplayExpression holds an expression, which is to say, the formula or recipe for how to calculate what should be displayed.

1 Like

I think this is partly where people go wrong:

(The same holds for the Hover Expression code box on the Hover Inspector.

I’ve started unpicking this with some new content in aTbRef. See this thread: Of expressions, actions and action code.