unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* References/locations
@ 2008-08-08  1:50 Maciek Godek
  2008-08-10  7:51 ` References/locations Stephen Compall
  0 siblings, 1 reply; 10+ messages in thread
From: Maciek Godek @ 2008-08-08  1:50 UTC (permalink / raw
  To: guile-user

Hi,
it's me again, asking silly questions.
This time I would like to know if there's
a simple way to store a reference to
a variable in another variable -- say,
an element of vector or hash table.

I imagine this could look like this:
(define v #(1 2 3))
(define v1 (vector-location v 1))
v1
: 2
(set! v1 10)
v
: #(1 10 3)

I've tried to do it using a "procedure with
setter", but the problem is that set! doesn't
evaluate its first argument (as long as it's a
symbol), so I'd have to wrap everything
up in macros to obtain:
(set! (vector-location v 1) 10)

Besides I think that the names "hash-ref"
and "vector-ref" are confusing, since they
don't return references, but values (therefore
the names like "vector-get" or "hash-get" would
be more apropreate)

I also wonder if there's any point for allowing
locations to any sorts of variables (similar to
pointers in C or pointers to C++), that is,
(define x 10)
(define y (location x))
(set! y 20)
x
: 20

I expect that this idea isn't new in the world of
lisp, but I didn't find any discussion on the web.
There are certainly some issues related with locations:
- they require special behavior of set! and define:
(set! y 20) could work in two different ways,
depending on whether y is a location or not
- what about "locations of locations"?
- how would it affect performance?
- what about multiple threads?

Regards
M.




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-08-21  5:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <cmu-lmtpd-5833-1218211546-4@mail-imap1.uio.no>
2008-08-08 18:34 ` References/locations Kjetil S. Matheussen
2008-08-10 23:00   ` References/locations Maciek Godek
2008-08-15 10:14   ` References/locations Maciek Godek
2008-08-15 13:55     ` References/locations Clinton Ebadi
2008-08-18  8:09       ` References/locations Maciek Godek
2008-08-18 16:15         ` References/locations Clinton Ebadi
2008-08-08  1:50 References/locations Maciek Godek
2008-08-10  7:51 ` References/locations Stephen Compall
2008-08-15  9:35   ` References/locations Maciek Godek
     [not found]   ` <e2ceda030808141732r524fc0cehb8ae7c6007550ea6@mail.gmail.com>
     [not found]     ` <m2wsihltfv.fsf@member.fsf.org>
     [not found]       ` <e2ceda030808200441q52d9858bv63323055e0f6308a@mail.gmail.com>
2008-08-21  5:05         ` References/locations Stephen Compall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).