Re: Next: eval in procedure-environment

From: Erick Gallesio <eg_at_saxo.essi.fr>
Date: Mon, 17 Mar 1997 12:33:06 +0100

> Olaf Gellert writes

> Any suggestions? Is there another way to create objects that
> have their own data and to which one can add (and maybe delete)
> functions after creation, which access the data? The word
> "meta object protocol" comes to my mind... (????) or maybe
> something like the "packages"-thing from the good ole
> Abelson/Sussman could be useful? Best would be something portable.
>

Thes is an undocumented function in STk, whiwh is called extend-environment
which allow to extend the current environment with the one you give. This
resolve the kind of problem you have I think.


    (define f
      (let ((data 0))
        (lambda (n)
          (set! data (+ data 1))
          (+ n data))))

    (define (f2)
      (extend-environment (procedure-environment f)
         (format #t "Value of format is ~S\n" data)))

In f2, the environment is extended with the one of f, and you can "see" the
data variable.

This function is undocumented, because I'm not sure it will be (at least with
this name) in future releases of STk. This kind of function breaks the
security you can have with closures over variable and it is whhy I'm reluctant
to officially add it in core STk. However it is very useful if you want
to make a debugger, or an inspector which need to display informations
about closures.....


                -- Erick
Received on Mon Mar 17 1997 - 12:34:19 CET

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST