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

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Tue Nov 3 21:02:50 EST 2009

But yours does more!

Robby

On Tue, Nov 3, 2009 at 7:45 PM, Jos Koot <jos.koot at telefonica.net> wrote:
> That's much simpler than I suggested ):
> Jos
>
>
> ----- Original Message ----- From: "Robby Findler"
> <robby at eecs.northwestern.edu>
> To: "Cheng-Chang Wu" <chengchangwu at yahoo.com>
> Cc: <plt-scheme at list.cs.brown.edu>
> Sent: Wednesday, November 04, 2009 2:34 AM
> Subject: Re: [plt-scheme] How to make a setter out of an identifier
>
>
> 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
>>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>
>


Posted on the users mailing list.