This is the mail archive of the guile@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: The GIMP! By gum, I forgot all about it!


forcer <forcer@mindless.com> writes:

> 
> On Thu, Oct 29, 1998 at 11:32:18PM -0500, Russell McManus wrote:
> >Scott Goehring <scott@poverty.bloomington.in.us> writes:
> >
> >> SIOD, or at least the SIOD in script-fu, lets you set! a previously
> >> unbound variable.  So (set! foo 5) is perfectly legal in script-fu,
> >> but raises an exception in guile.  Unfortunately, a number of
> >> script-fu script authors have made use of this anomalous behavior.
> >
> >Maybe this quick hack can be the beginning of a solution (guile
> >specific code):
> >
> >(define %set! set!)
> >(defmacro set! (name value)
> >  `(begin
> >     (if (not (defined? (quote ,name)))
> >	 (define ,name #f))
> >     (%set! ,name ,value)))
> 
> Uhm, why do you emulate define? :) 

Well, I wasn't thinking about it too hard, and I was just trying to
code a version of set! that does what siod's does.

Here is another version that adds your additional constraint of set!
returning the supplied value, and that makes sure that the value is
only evaluated once:

(define %set! set!)
(defmacro set! (name value)
  (let ((%value (gensym)))
    `(begin
       (if (not (defined? (quote ,name)))
	   (define ,name #f))
       (let ((,%value ,value))
	 (%set! ,name ,%value)
	 ,%value))))

-russ