Skip to main content

Boolean Class

Boolean is Alia's built-in boolean class, used to represent the logical values true and false.

Creating Booleans​

Literals​

const bool1 = true
const bool2 = false

Constructor Form​

const bool3 = new Boolean [true]
const bool4 = Boolean[true]
const bool5 = Boolean[1] ~ outputs true
const bool6 = Boolean[0] ~ outputs false

Instance Methods​

toString​

Returns the string corresponding to the boolean value, with signature alias -> String.

const bool = true
print call bool.toString ~ outputs 'true'

valueOf​

Returns the primitive value of the boolean, with signature alias -> Boolean.

const bool = true
print call bool.valueOf ~ outputs true

toNumber​

Returns the numeric value corresponding to the boolean, with signature alias -> Number. true corresponds to 1, and false corresponds to 0.

const bool = true
print call bool.toNumber ~ outputs 1
const no = false
print call no.toNumber ~ outputs 0

toArray​

Returns a single-element array containing the boolean, with signature alias -> Array.

const bool = true
print call bool.toArray ~ outputs Array [Boolean true]

toCode​

Returns the code-form string of the boolean, with signature alias -> String.

const bool = true
print call bool.toCode ~ outputs 'true'

toDescription​

Returns the description string of the boolean, with signature alias -> String.

const bool = true
print call bool.toDescription ~ outputs 'Boolean true'

Logical Operations​

Logical AND (&)​

const a = true
const b = false
print a & b ~ outputs false

Logical OR (|)​

const a = true
const b = false
print a | b ~ outputs true

Logical NOT (!)​

const a = true
print !a ~ outputs false

Conditional Judgment​

Booleans map directly to conditional judgment:

const age = 18
const isAdult = age >= 18

if isAdult {
print 'adult'
} else {
print 'minor'
}

Ternary Operator​

const age = 18
const status = age >= 18 ? 'adult' : 'minor'
print status

Example Code​

const bool1 = true
const bool2 = false

print 'Boolean 1: ' .. (call bool1.toString)
print 'Boolean 2: ' .. (call bool2.toString)

print 'true & false: ' .. (true & false)
print 'true | false: ' .. (true | false)
print '!true: ' .. (!true)

const a = 10
const b = 5
const isGreater = a > b
print 'a > b: ' .. (call isGreater.toString)

const age = 18
const isAdult = age >= 18

if isAdult {
print 'adult'
} else {
print 'minor'
}

const score = 85
const grade = score >= 60 ? 'pass' : 'fail'
print 'Grade: ' .. grade

const num = 1
const boolFromNum = num as Boolean
print 'Converted from number: ' .. (call boolFromNum.toString)

const str = ''
const boolFromStr = Boolean[str]
print 'Converted from empty string: ' .. (call boolFromStr.toString)

Next Steps​