This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: tie variable
- To: Keisuke Nishida <kxn30 at po dot cwru dot edu>
- Subject: Re: tie variable
- From: Jost Boekemeier <jostobfe at linux dot zrz dot TU-Berlin dot DE>
- Date: 04 Apr 2000 01:35:56 +0200
- Cc: guile at sourceware dot cygnus dot com
- References: <m3ya7lx4i5.fsf@kei.cwru.edu> <m3ln2wsa0j.fsf@kei.cwru.edu>
Keisuke Nishida <kxn30@po.cwru.edu> writes:
> > 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)
Excuse me but what does "-> (global-ref ...)" mean?
environment-ref looks up a variable binding for `user-full-name' in
`lisp-environment' and returns a value. If this value is
a closure and you invoke the closure, it will look up bindings
in the environment in which it was defined.
Also I don't understand why you want to have two separate variables
in the lisp and scheme environment. Don't you translate
lisp to scheme code?
Jost