Debugging in Depth
In cases when debugging programs that are on the same directory, it is useful to name the debug file by the program name:
@debug_file appname + '.debug'
@ 'this debug file was created by Tyl system, upon running program: `' + appname + '.tyl`'
We make use of appname system variable to construct debug file name.

@debug_file debug function merely sets the debug file name. If there is no debug statement other than @debug_file, then the debug file will not be created!

Debug data is saved upon each debug call:
names 'Lili' 'Mili' 'Nili'
index 10 ~ @ names index
While looping in a range that exceeds names list length, eventually the call to: names index, will result in an "Index out of range" error, but the debug data is saved upon each @ call:


The @k function is also useful for any key value parameters:
names 'Lili' 'Mili' 'Nili'

@k 'the program file name is' appname + '.tyl'
@k 'the list is' names
@k 'the second item is' names 1
All '@k key value' calls will be logged in the format: 'key: value':

the program file name is: app.tyl
the list is: [ 'Lili', 'Mili', 'Nili' ]
the second item is: Mili

So to log list indexes and values:
names 'Lili' 'Mili' 'Nili'
names_len len names
index names_len ~ @k index names index
In line: @k index names index, the key will be an index, and the value will be the item of names list in index position:

0: Lili
1: Mili
2: Nili

During program coding and debugging, sections of code raise errors, and it is needed to stop the program immidiately. We can use the @exit debug function.

Consider this Log Calculator program:
print log 8

log x:
p 0.5
delta 0.01
eq_delta 0.01

stop_ctr 1000

on ~
@k p
  result math.power 10 p
  diff x - result
  abs_diff math.abs diff
@k diff

  abs_diff > eq_delta ?
   diff > 0 ?
    p ++ delta
    p -- delta
stop_ctr --
not stop_ctr ? @exit


We added log data of p and diff variables, and a stop counting mechanism, with @exit debug function.

Running the program, and checking the log:

p: 0.5
diff: 4.83772233983162
p: 0.51
diff: 4.76406343070372
p: 0.9
diff: 0.0567176527571798
p: 0.91
diff: -0.12830516164099
p: 0.9
diff: 0.0567176527571798

As it becomes apparent, p toggles between 0.9 and 0.91 endlessly. To fix that, change delta 0.01 to delta 0.001, thus causing p to reach the right result. Now you can safely remove all debug code.