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: Eric Moore <moore at chem dot cmu dot edu>
- Date: Tue, 14 Mar 2000 05:55:27 -0500 (EST)
- Cc: guile at sourceware dot cygnus dot com
- References: <m3ya7lx4i5.fsf@kei.cwru.edu>
>>>>> "Keisuke" == Keisuke Nishida <kxn30@po.cwru.edu> writes:
Keisuke> Now, the value of user-full-name has to be always the same as
Keisuke> that of Lisp. Also, changing the value of user-full-name has
Keisuke> to also change the value of Lisp's one. For now I use the
Keisuke> following expressions for this purpose:
Keisuke> (global-ref user-full-name) (global-set! user-full-name
Keisuke> value)
Keisuke> But this is rather tedious. I'd like to write:
Keisuke> user-full-name (set! user-full-name value)
Keisuke> Can I do this with connections to the value of the Lisp
Keisuke> variable?
Well, you could do:
(defmacro import-global (sym)
`(define ,sym
(make-procedure-with-setter (lambda () (global-ref (quote ,sym)))
(lambda (x) (global-set! (quote ,sym) x)))))
then do:
guile> (import-global user-full-name)
then you could access the variable like this:
guile> (display (user-full-name))
Eric Moore
guile> (set! (user-full-name) "Eric the Moore, Squire of the Lambda Calculus")
guile> (display (user-full-name))
Eric the Moore, Squire of the Lambda Calculus
Obviously, you can chenge the syntax of import-global to just return
the procedure-with-setter and define it yourself... I don't think
there is (or should be) a way to just have (set! variablename value)
do anything special, but hey, it's lisp, what's an extra pair of
parens between friends?
-Eric