[plt-scheme] Reverse engineering of procedures

From: Arie van Wingerden (apwing at zonnet.nl)
Date: Mon Mar 14 10:33:09 EST 2005

Hi Schemers,

since some time I am working through 'The Little Schemer' using DrScheme.
Now I have reached the function multirember&co on page 137 and I am 
kinda stuck; below is the code.

(define multirember&co
  (lambda (a lat col)
    (cond
      ((null? lat)
       (col '() '()))
      ((eq? (car lat) a)
       (multirember&co a
                       (cdr lat)
                       (lambda (newlat seen)
                         (col newlat (cons (car lat) seen)))))
      (else
       (multirember&co a
                       (cdr lat)
                       (print (lambda (newlat seen)
                         (col (cons (car lat) newlat) seen))))))))

(define a-friend
  (lambda (x y)
    (null? y)))

(multirember&co 'tuna '(tuna) a-friend)

What I cannot really grasp at the moment is what exactly the generated 
function (col) will be upon the next call of multirember&co.
To be precise, given the piece of code:
      ((eq? (car lat) a)
       (multirember&co a
                       (cdr lat)
                       (lambda (newlat seen)
                         (col newlat (cons (car lat) seen)))))
what is the form of the lambda afterwards (just before calling 
multirember&co again?

So I tried to find a way to debug.
I already found out:
    - the stepper does not work because lambda's are being used without 
being a definition
    - that trace.ss does not help, since the col argument to 
multirember&co only shows the name of the generated procedure col,
       being something like #<procedure:657:23>

So, what I really need is a form which, given something like 
#<procedure:657:23> gan show me the sourcecode for that procedure and in 
general: what other ways of debugging are available in DrScheme?

Thanks in advance,
    Arie




Posted on the users mailing list.