Written by

Lead Technical Analyst at Missouri Health Connection
Question Scott Beeson · Jan 21, 2016

How do I set a boolean?

Is it just set varName = 1 or is there an actual true/false value?

Comments

Dmitry Maslennikov · Jan 21, 2016

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

0
Scott Beeson · Jan 21, 2016

So set the boolean variable to 0 for false and basically anything else for true?  I'll continue using 1 and 0, thanks!

0
Ray Fucillo · Jan 22, 2016

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

0
Scott Beeson  Jan 26, 2016 to Vitaliy Serdtsev

I think I see, you'd have to do this first though, right?

#Define YES "1"
#Define NO "0"
0
Dmitry Zasypkin  Jan 26, 2016 to Scott Beeson

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
  }
}

0
Dmitry Zasypkin · Jan 26, 2016

And you can use $$$YES and $$$NO inside a class without adding"#include %systemInclude" to it.

0
Ray Fucillo · Jan 26, 2016

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...

0
Timur Safin  Jan 26, 2016 to Ray Fucillo

Not exactly nowadays, as I see - %systemInclude is included at %Library.Base level (1 level above the %Library.RegisteredObject).

But idea is the same :)

0
Dmitry Maslennikov  Jan 26, 2016 to Timur Safin

And even if you don't extend any classes, it any case will be hidden extend with %Library.Base. and %systemInclude still be included.

0
Stefan Cronje · Oct 20, 2018

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

0