guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: References/locations


From: Maciek Godek
Subject: Re: References/locations
Date: Fri, 15 Aug 2008 12:14:05 +0200

Kjetil:

> Well, here's a relatively clean way, I think:
>
> (define-macro (location name)
>   (define new-val (gensym))
>   `(lambda (,new-val)
>       (set! ,name ,new-val)))
>
> (define old-set! set!)
>
> (define-macro (set! a b)
>  `(if (procedure? ,a)  ;; Needs a better check.
>       (,a ,b)
>       (old-set! ,a ,b)))
>
>
> guile> (define x 10)
> guile> (define y (location x))
> guile> (set! y 20)
> guile> x
> 20
> guile>

I just realized that this is only a partial solution.
Continuing the above example,
guile> y
#<procedure #f (#syntmp-\ g1336-76}#)>

I don't know how to solve it: the problem is that
you actually can't bind a function call to a variable.

But even without it, the line
(define old-set! set!)
breaks:
ERROR: invalid syntax set!

I've been thinking of implementing this "location" stuff
as a smob, but you've got the point that it is (probably)
impossible to implement the location system without
redefining set! and define.

Regards
M.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]