[plt-scheme] Re: applying set! on the contents of a variable

From: Majorinc, Kazimir (kazimir at chem.pmf.hr)
Date: Sun Sep 30 10:57:17 EDT 2007

harsha wrote:
> thanks, for the replies, the hash-table seems to be a good idea, i'll
> probably go with that
>>> (define-macro (set!! p e)(list 'set! (eval p) e))
> that's a pretty neat macro, if only there was some way of making eval
> respect scope...
We can at least make local namespaces. Few
macros good only to show what's possible. Real usage would
require lot of quotes and evals. As Carl said
(require (lib "defmacro.ss")) or Pretty Big language.
And really, why it is not design decision that eval supports
local variables? What is the reasoning behind that
limitation of, I believe, the most powerful feature or Scheme?
;_____________________________________
(define-macro (define# p e)
  (list 'eval (list 'quote (list 'define p e))))
(define-macro (display# p)
  (list 'display (list 'eval (list 'quote p))))
(define-macro (set#!! p e)
  (list 'eval
        (list 'append
              (list 'list ''set!)
              (list 'list (list 'eval (list 'quote p)))
              (list 'list (list 'eval (list 'quote e))))))
(define-macro (define-in-namespace . args)
  (list
    'define (car args)
    (list 'let
          (list
            (list
              (string->symbol
               (string-append
                 (symbol->string (car (car args))) "#"))
              '(make-namespace)))
          (append
            (list 'parameterize
                  (list
                    (list 'current-namespace
                          (string->symbol
                           (string-append
                             (symbol->string
                               (car (car args))) "#")))))
            (cdr args)))))
;______________________________________
(define# y "start")
(define# x 'y)
(set#!! x "top-level did it.\n")
(display# y)

(define-in-namespace (my-function)
 (define# y "middle")
 (define# x 'y)
 (set#!! x "my-function did it.\n")
 (display# y))

(my-function) 
(display# y)
;______________________________________
;top-level did it.
;my-function did it.
;top-level did it.









Posted on the users mailing list.