[plt-scheme] Displaying the function body

From: Ron Stanonik (stanonik at gmail.com)
Date: Tue Jan 4 11:36:11 EST 2005

On Thu, 9 Dec 2004 11:49:48 -0800, Dmitriy.Zavin at infineon.com
<Dmitriy.Zavin at infineon.com> wrote:
> I was wondering how one would go about displaying the function body of a
> function that is currently defined? (something equivalent to Tcl's
> "info body <func>"

I had a similar need, but only for lambdas I created.
Mathew Flatt responded with

(module new-lambda mzscheme

  (provide new-lambda ;(rename new-lambda lambda)
           procedure-body
           procedure-args)

  (define-values (struct:ap make-annotated-proc annotated-proc? ap-ref ap-set!)
    (make-struct-type 'anotated-proc #f 3 0 #f null #f 0))

  (define procedure-args (make-struct-field-accessor ap-ref 1))
  (define procedure-body (make-struct-field-accessor ap-ref 2))

  (define-syntax new-lambda
    (syntax-rules ()
      [(_ args . body)
       (make-annotated-proc (lambda args . body) 'args 'body)]))

)

Hope it helps.

Ron



Posted on the users mailing list.