[plt-scheme] recover a procedure body?

From: Doug Orleans (dougo at ccs.neu.edu)
Date: Mon Nov 25 07:45:08 EST 2002

Matthew Flatt writes:
 > If you have control over the context where the procedure is created,
 > you can redefine `lambda' to keep that information.
 > 
 >  ; This example uses v202.2 procedure structures
 >  (module new-lambda mzscheme
 > 
 >   (provide (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)])))

I tried this, but it interacts badly with the class system:

  Welcome to MzScheme version 202.5, Copyright (c) 1995-2002 PLT
  > (require "new-lambda.scm")
  > (procedure-args (lambda (x) x))
  (x)
  > (require (lib "class.ss"))
  > (class object% (define/public id (lambda (x) x)))
  STDIN::137: class*/names: bad form for method definition at: (make-annotated-proc (lambda (x) x) (quote (x)) (quote (x))) in: (class*/names (this super-instantiate super-make-object) object% () (define/public id (lambda (x)...

Is there any way to tell the class macros not to expand new-lambda?
Barring that, is there a way to make the new-lambda macro behave
differently if it's in the context of a class definition?

--dougo at ccs.neu.edu


Posted on the users mailing list.