[plt-scheme] How to make a setter out of an identifier
Hi,
I am new to the brave scheme world, and trying hard to understand the secrets of macro.
I want to do the following: take an identifier and make a setter out of the identifier.
For example,
(define kk 0)
(make-setter kk)
should give me a set-kk! which can be used to set the value of kk.
The best macro I can image is
(define-syntax make-setter
(lambda (x)
(syntax-case x ()
((make-setter id)
(with-syntax
((def
(datum->syntax
(syntax k)
`(define (,(string->symbol (string-append "set-" (symbol->string 'id) "!")) a-value) (set! id a-value)))))
(syntax def))))))
___________________________________________________
您的生活即時通 - 溝通、娛樂、生活、工作一次搞定!
http://messenger.yahoo.com.tw/