[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Procedure definition



Matthew Flatt <mflatt@cs.utah.edu> writes:

> Quoting Manuel Giraud:
> >         Is there a way to retrieve the "definition" of a function in
> >         MzScheme? I explain : 
> > 
> >         > (define (f n) (* n n))
> >         > (something-like-global-defined-value 'f)
> >           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >         Here, I want to get '(lambda (n) (* n n)) and not just
> >         #<procedure:f>
> 
> No. The best strategy for getting that information depends on what you
> want to do with it.
> 
> Below is one approach in v200. A more general approach would be
> something like the way errortrace works: set the eval handler to one
> that expands expressions, then replaces each `lambda' in the expanded
> expression with something like `wrapper-lambda', then calls the
> original eval handler.
> 

Thank you very much. I finally mix both some of your code and the
approach used in errortrace. I first worried about the fact that
hash-table's keys are procedures (not just symbols) because every
lambdas I use was it the hash-table [1] : but I can see that
everything is correctly garbage-collected, so it's OK.

[1]:
        ;;; Loading the new eval-handler ...
        (require-library "record-source.scm" "personal")

        ;;; ... so the ht hash-table is clean ...
        (hash-table-map ht (lambda (a b) (display b) (newline)))

        ;;; ... no because I've used a lambda.
        ---> (#%lambda (a b) (display b) (newline))
             (#<void>)

-- 
"Never imagine yourself not to be otherwise than what it might appear
to others that what you were or might have been was not otherwise than
what you had been would have appeared to them to be otherwise"
  The Duchess

_Manuel Giraud_