Tyl Programming Language
▶ CONDITIONAL STATEMENT - PART 3
Variable Condition
Variable condition statement is any statement that yields a scalar variable

Each scalar variable has a boolean interpretation:
name 'Kazuo'
counter 0
sun_is_hot

print 'name has value: ' + ( name ? )
print 'counter is not zero: ' + ( counter ? )
print 'sun_is_hot: ' + sun_is_hot

name has value: True
counter is not zero: False
sun_is_hot: True
quantities 10 0 8

quantities 0 ? print 'First quantity is not zero' print 'First quantity is zero'

quantities 1 ? print 'Second quantity is not zero' print 'Second quantity is zero'
First quantity is not zero
Second quantity is zero
get_me_true »

get_me_false »

main »
 is_true

 is_true ? print 'is_true: ' + get_me_true print 'is_true: ' + get_me_false

 is_true

 is_true ? print 'is_true: ' + get_me_true print 'is_true: ' + get_me_false

is_true: True
is_true: False
It is good practise to use functions that act according to a boolean parameter:
print_state state » print 'is_true: ' + state

print_by_state state » state ? print 'The state is true.' print 'The state is false.'

main »
 is_true
print_state is_true
print_by_state is_true

 is_true
print_state is_true
print_by_state is_true
is_true: True
The state is true.
is_true: False
The state is false
Here's User Name Validator:
validate name »
 is_valid

 name ? is_valid

 is_valid

main »
 user_name ''

validate user_name ?
  print 'user_name validated OK.'
  print 'continue with registration...'
  
  print 'user_name is not valid!'

user_name is not valid!
If we change the user_name assignment line to: user_name 'Timothy':

user_name validated OK.
continue with registration...
validate function can be shortened to:
validate name » name ?


PART 2
PART 4