Not anything else. True values are any that evaluate numerically as non-zero. Strings evaluate numerically by treating the beginning of the string as a number until a non-numeric character is encountered. So "1 avocado" evaluates numerically as 1 and "-.04abc" evaluates numerically as -0.04. Both of these strings are true. "basil" is just as false as the null string.
I just want to point out that the class thing that folks have been mentioning isn't magical. It's that RegisteredObject includes %systemInclude and most classes have that in their heirarchy. I believe that nothing is implicitly included in an Abstract class...
In Cache uses typeless language. So in some cases such as in command IF
if varName write "true" else write "false"
or any other logical operations any non zero values will be as true values.
and '1 will give a 0
So set the boolean variable to 0 for false and basically anything else for true? I'll continue using 1 and 0, thanks!
Not anything else. True values are any that evaluate numerically as non-zero. Strings evaluate numerically by treating the beginning of the string as a number until a non-numeric character is encountered. So "1 avocado" evaluates numerically as 1 and "-.04abc" evaluates numerically as -0.04. Both of these strings are true. "basil" is just as false as the null string.
For more discussion see the docs here:
http://docs.intersystems.com/cache20152/csp/docbook/DocBook.UI.Page.cls?KEY=GCOS_types#GCOS_types_booleans
and
http://docs.intersystems.com/cache20152/csp/docbook/DocBook.UI.Page.cls?KEY=GCOS_types#GCOS_types_nonnumasnum
Thanks
Converted to an answer
For clarity in code you can write:
set varName = $$$NO ; 0
set varName = $$$YES ; 1
See ObjectScript Macros and the Macro Preprocessor
I think I see, you'd have to do this first though, right?
No, you wouldn't, - if you're inside a class you can just use $$$YES/$$$NO without adding #include or #define:
Class temp.TestTest
{
ClassMethod test()
{
write $$$YES
}
}
And you can use $$$YES and $$$NO inside a class without adding "#include %systemInclude" to it.
I just want to point out that the class thing that folks have been mentioning isn't magical. It's that RegisteredObject includes %systemInclude and most classes have that in their heirarchy. I believe that nothing is implicitly included in an Abstract class...
Not exactly nowadays, as I see - %systemInclude is included at %Library.Base level (1 level above the %Library.RegisteredObject).
But idea is the same :)
And even if you don't extend any classes, it any case will be hidden extend with %Library.Base. and %systemInclude still be included.
You cab create a new include file or add the following to one of your existing include files
#define true 1
#define false 0
Then in your class, include this include file and use as follows:
set varName = $$$true