This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: tie variable


Hello,

I wrote:
> I have a question of how to make a special variable in Scheme
> that is like a tie variable in Perl.  Is there any way to call
> a certain function whenever a variable is referred or modified?

>   (global-ref user-full-name)
>   (global-set! user-full-name value)
> 
> But this is rather tedious.  I'd like to write:
> 
>   user-full-name
>   (set! user-full-name value)

Could I do this by using the new top-level environment scheme?

  (define lisp-environment (make-lisp-environment))

  (environment-ref lisp-environment 'user-full-name)
    -> (global-ref 'user-full-name)

  (environment-set! lisp-environment 'user-full-name value)
    -> (global-set! 'user-full-name value)

And using this at top level, will those variables defined in
the lisp-environment be referred/modified appropriately?
If this can be done, this works just like tie variables.

Thanks,
Keisuke Nishida

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]