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


>>>>> "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

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