Path: utzoo!attcan!uunet!bu.edu!rpi!zaphod.mps.ohio-state.edu!usc!cs.utexas.edu!sun-barr!ccut!s.u-tokyo!is.s.u-tokyo!ken-w From: ken-w@is.s.u-tokyo.ac.jp (WAKITA Ken) Newsgroups: comp.lang.scheme Subject: Re: trace in xscheme Message-ID: <1520@malta.is.s.u-tokyo.ac.jp> Date: 30 Oct 90 09:07:12 GMT References: <28787@boulder.Colorado.EDU> Sender: news@is.s.u-tokyo.ac.jp Reply-To: ken-w@is.s.u-tokyo.ac.jp Distribution: comp Organization: Dept. of Information Science, the Univ. of Tokyo, Japan. Lines: 86 In-reply-to: grunwald@foobar.colorado.edu's message of 27 Oct 90 12:56:05 JST In article <28787@boulder.Colorado.EDU> grunwald@foobar.colorado.edu (Dirk Grunwald) writes: > From: grunwald@foobar.colorado.edu (Dirk Grunwald) > Newsgroups: comp.lang.scheme > Date: 27 Oct 90 12:56:05 JST > Sender: news@boulder.Colorado.EDU > Reply-To: grunwald@foobar.colorado.edu > Distribution: comp > Organization: University of Colorado at Boulder > Lines: 205 > > > I'm using xscheme-0.22 for a class in programming languages. There's > no trace facility, so I wrote one. I'm wondering if anyone has written > any other debugging facilities; my students are having a tough time > with debugging xscheme programs. ELK does not provide trace facility. So, I've also written similar, shorter, but a bit dangerous program. Though it contains several known bugs (it can't trace macros and primitive procedures) it is useful. I also have written a toplevel eval-read-print loop to support transcript-on/off facility. An interested reader can request via E-mail to: ken-w@is.s.u-tokyo.ac.jp ---------------------------------------------------------------------- (define trace) (define untrace) (let () (define trace-list '(())) (define (reset-trace) (set! trace-list '(()))) (define-macro (the-trace func) `(let ((the-func (eval ,func)) (result #v)) (if (assoc ',func ,trace-list) (error 'trace "~s already trace on." ,func)) (if (not (compound? ,func)) (error 'trace "wrong argument type ~s (expected compound)" (type ,func))) (set! ,trace-list (cons () (cons (cons ',func the-func) (cdr ,trace-list)))) (set! ,func (lambda param-list (format #t "# Entering ~s~%" (cons ',func param-list)) (set! result (apply the-func param-list)) (format #t "# Exiting ~s ==> ~s~%" (cons ',func param-list) result) result)))) (print (type the-trace)) (define-macro (the-untrace func) `(let ((the-func (assoc ',func ,trace-list))) (define (remove! func) (let ((prev ,trace-list) (here (cdr ,trace-list))) (while (and here (not (eq? func (caar here)))) (set! prev here) (set! here (cdr here))) (if (not here) (error 'remove "item ~s not found." func) (set-cdr! prev (cdr here))))) (if the-func (begin (remove! ',func) (set! ,func (cdr the-func)))))) (print (type the-untrace)) (set! trace the-trace) (set! untrace the-untrace)) ---------------------------------------------------------------------- -- WAKITA Ken (ken-w@is.s.u-tokyo.ac.jp) Masuda Group., Dept. of Info. Sci., Univ. of Tokyo.