[plt-scheme] redefining set!

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Mon Jun 18 16:09:07 EDT 2007

Hans Oesterholt-Dijkema wrote:

> Is it possible to redefine, or override set!?
> I'd like to extend the behaviour of the set!
> operator to act context sensitive.

Here is how to define your own set!.

(module mzscheme-my-set! mzscheme
   (provide (all-from-except mzscheme set!)
            (rename my-set! set!))

   (define-syntax (my-set! stx)
     (syntax-case stx ()
       [(_ var expr)
        (syntax/loc stx
          (set! var (+ expr 1)))])))

(module A mzscheme-my-set!
   (define a 1)
   (set! a 42)
   (display a)
   (newline))

(require A)


-- 
Jens Axel Søgaard



Posted on the users mailing list.