[plt-scheme] How to make a setter out of an identifier

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Tue Nov 3 20:34:57 EST 2009

How about this:

(define-syntax-rule (make-setter kk) (lambda (x) (set! kk x)))

Robby

2009/11/3 Cheng-Chang Wu <chengchangwu at yahoo.com>:
> 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/
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


Posted on the users mailing list.