debuggingrecursionchicken-scheme

What is the proper way to visualize recursive function calls with CHICKEN?


I'm new to scheme (my lisp experience limited to configuring emacs) and I'm trying to better understand recursion and conses. I'd like to get debugging output, showing each call to a function, so I can better visualize the recursion.

Noodling around, I came up with

(define (last lst)
  (if (null? (cdr lst))
      (car lst)
      (last (cdr lst))))

to get the last member of a list. It seems to work. To debug this, I came up with

(define (last lst)
  (print "Debug: " lst)
  (if (null? (cdr lst))
      (car lst)
      (last (cdr lst))))

which for (last '(a b c d)) results in

Debug: (a b c d)
Debug: (b c d)
Debug: (c d)
Debug: (d)

In CHICKEN, is there a more idiomatic way to get debugging output on each call to the function, so I can see how the calls to the function progress?


Solution

  • Nope, that's basically how I do it too. If you want something more convenient, you could try the trace egg which can automatically give you call nesting and input parameters.

    If you want to get a bit fancier, you could use the "Feathers" debugger which comes shipped with CHICKEN.