guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Restoration of Session Variables


From: Volkan YAZICI
Subject: Re: Restoration of Session Variables
Date: Sat, 21 Oct 2006 00:15:00 +0300
User-agent: Mutt/1.4.2.1i

On Oct 20 09:49, Neil Jerram wrote:
> Volkan YAZICI <address@hidden> writes:
> > I'm executing seperate procedures in the same Guile session initialized
> > by scm_init_guile(). Just after initialization, some global definitions
> > get loaded. While executing supplied procedures sequentially, I want to
> > restrict their access to some variables. Namely I want to set some
> > definitions as read-only. Is this possible?
> >
> > I tried playing with fluids and dynamic states but couldn't figure out a
> > solution. I'd be very appreciated to hear any kind of suggestion.
> 
> Not sure I completely understand.  Can you give an example of one of
> the globals that you want to be read-only, and of an eval that would
> try - and should fail - to change it?

I've solved my problem by using fluid-let. Yes, there's no fluid-let in
Guile, but we've define-syntax and make-fluid:

(define-syntax fluid-let
  (syntax-rules ()
    ((fluid-let ((var1 val1)
                 (var2 val2)
                 ...)
       body1
       body2
       ...)
     
     (let ((var1 (make-fluid))
           (var2 (make-fluid))
           ...)
       (fluid-set! var1 val1)
       (fluid-set! var2 val2)
       ...
       (let ((var1 (fluid-ref var1))
             (var2 (fluid-ref var2))
             ...)
         body1
         body2
         ...)))))

(define globally-editable #t)
(define protect-me #t)

(fluid-let ((protect-me protect-me))
  (set! globally-editable #f)
  (set! protect-me #f))

(display globally-editable)(newline)
#f
(display protect-me)(newline)
#t

As you can see, we protected the value of protect-me even it looks to
the fluid-let scope that it modified protect-me.


Regards.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]