Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Documentation and Tutorials >> Implicit truth testing with ^value
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1263680351

Message started by Amber Vaesca on Jan 16th, 2010, 5:19pm

Title: Implicit truth testing with ^value
Post by Amber Vaesca on Jan 16th, 2010, 5:19pm

Something that probably ought to mentioned in the documentation is that the new `^value` template code does not return true or false depending on the attribute state. It is described as being essentially synonymous with `^get[For]`, but in that one aspect it is not. The following used to return false if the attribute was “empty” according the rules of `^exists`:


Code:
^if(^get(SomeAttribute)^)^


…but


Code:
^if(^value($SomeAttribute)^)^


…does not.

Perhaps I was a bit of an eccentric in that I used this method for truth testing, but it might deserve mention that `^exists` is now the preferred syntax for this type of simple conditional. And that old templates will need to be adjusted accordingly.

Update: Another peculiarity I’m running into is that `^exists` doesn’t seem to work with all data types. For instance, with sets it returns truth even if the set is empty. It seems the only “simple” way to test for false or empty sets is to continue using the old `^get` method.

Title: Re: Implicate truth testing with ^value
Post by Mark Anderson on Jan 16th, 2010, 5:53pm

True, but regarding your first example a more normal export-code-based conditional is:
^if(MyString)^^get(MyString)^^else^Stuff^endIf^

IOW, ^if(MyString)^ not ^if(^get(MyString)^)^.

That said, agree that different outcomes from attribute name or ^get conditionals and ^value conditionals it would be worth noting. Probably one for submission to the cookbook too.

Title: Re: Implicit truth testing with ^value
Post by Amber Vaesca on Jan 16th, 2010, 10:20pm

Yes, I don't remember why I started using the more expanded version. Perhaps at some point (circa v3), using ^get was safer for all data types or something and I just got into the habit of it.

Title: Re: Implicit truth testing with ^value
Post by Mark Anderson on Jan 17th, 2010, 8:47am

Testing sets as bare attribute name works for tests, even if exists doesn't; use a $ prefix if in action code.

These suggested positive/negative match export syntaxes for sets:
 ^if(MySet)^truth^else^not truth^endIf^
 ^if(!MySet)^truth^else^not truth^endIf^
 ^if(^not(MySet)^)^truth^else^not truth^endIf^

…both work. I suggest changing your code to the above with the '!' syntax being the preferred negative test form as it better mirrors internal syntax.

Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com) » Powered by YaBB 2.2.1!
YaBB © 2000-2008. All Rights Reserved.