home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / tile.lzh / tile.1 / tst / debugger.tst < prev    next >
Encoding:
Text File  |  1990-07-26  |  875 b   |  71 lines

  1. .( Loading Debugger test...) cr
  2.  
  3. #include debugger.f83
  4.  
  5. debugger 
  6.  
  7.  
  8. .( 1: Define a debuggable tail-recursive function) cr
  9.  
  10. : foo ( n -- )
  11.   ?dup if ." foo " 1- tail-recurse else cr then
  12. ;
  13.  
  14. 12 foo 
  15. trace foo
  16. 12 foo 
  17. .profile
  18.  
  19.  
  20. .( 2: Redefine it as a recursive function) cr
  21.  
  22. : fie ( n -- )
  23.   ?dup if ." fie " 1- recurse else cr then
  24. ;
  25.  
  26. 12 fie 
  27. trace fie
  28. 12 fie 
  29. .profile
  30.  
  31.  
  32. .( 3: Run the break point function) cr
  33.  
  34. ( Only in interactive mode
  35.  
  36. break foo
  37.  
  38. 10 foo a .s cr 
  39. 10 foo c .s cr
  40. 10 foo e r .s cr
  41.  
  42. )
  43.  
  44.  
  45. .( 4: Fibonanci number function; recursive and tail recursive) cr
  46.  
  47. : fib ( n -- m)
  48.   dup 1 > if dup 1- recurse swap 2- recurse + then
  49. ;
  50.  
  51. trace fib
  52. 10 fib . cr
  53. .profile
  54.  
  55. : fib-tail ( a b c -- m)
  56.   ?dup if 1- -rot over + swap rot tail-recurse else nip then
  57. ;
  58.  
  59. : fib-iter ( n -- m)
  60.   1 0 rot fib-tail
  61. ;
  62.  
  63. trace fib-tail
  64. trace fib-iter
  65. 10 fib-iter . cr
  66. .profile
  67.  
  68. forth only
  69.  
  70.  
  71.