[plt-scheme] redefining set!

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Mon Jun 18 17:38:25 EDT 2007

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.

-- 
Jens Axel Søgaard



Posted on the users mailing list.