[plt-scheme] redefining set!

From: Hans Oesterholt-Dijkema (hdnews at gawab.com)
Date: Mon Jun 18 17:54:23 EDT 2007

Hmm,

If instead of defining a procedure, I'd define a
macro, I would be able to do

(define x (cl 5))

instead of  (define-instance x (cl 5))

However. How can I create a result that will
be able to be called like a macro. I cannot return
a macro as a value can I?

So I can associate cl with m alright. But that would
require defining something like:

cl->

wouldn't it?

And then, "transforming" (-> x m 8) to something like
(cl-> x m 8). However, how can I turn -> into cl->?

--Hans




Jens Axel Søgaard schreef:
> Hans Oesterholt-Dijkema skrev:
>> I didn't say it quite right. I'd really like to do something
>> like this:
>>
>> (define-syntax def-class
>>  (syntax-rules ()
>>    ((_ (f e1 ...) (member1 expr1) ...)
>>     (begin
>>       (define (f e1 ...)
>>         (define member1 expr1)
>>         ...
>>
>>         (define-syntax obj
>>           (syntax-rules ()
>>             ((_ member1 expr) (set! member1 expr))
>>             ...))
>>
>>         (syntax obj))))))
>>
>> (def-class (cl a) (m (* a a)))
>> (define x (cl 5))
>> (-> x m 8)
>>
>> I'd like somehow to (-> x m 8) to set the member m to 8,
>> using syntax expansion. I'm however not sure how to reach
>> that.
>
> If we assume that
>
>     (define x (cl 5))
>
> binds x to a value at runtime, then in
>
>     (-> x m 8)
>
> there is no way we at macro expansion time can know
> that x is bound to a the class cl. This means that
> we can't know which class m belongs to.
>
> If you on the other hand provide the class, as in
>
>     (-> x cl m 8)
>
> then from cl and m you have enough information
> at macro expansion time.
>
> If you introduce a mechanism like
>
>   (define-instance x (cl 5))
>
> which records that x is of class cl, then
> you have the information you need to make
>
>     (-> x m 8)
>
> work.
>



Posted on the users mailing list.