Mutable reference to a structure field
From: Alex Drummond (a.drummond_at_ucl.ac.uk)
Date: 06/19/04
- Next message: Brian Downing: "Re: Mutable reference to a structure field"
- Previous message: Duane Rettig: "Re: Was not making tail recursion elmination a mistake?"
- Next in thread: Brian Downing: "Re: Mutable reference to a structure field"
- Reply: Brian Downing: "Re: Mutable reference to a structure field"
- Reply: Barry Margolin: "Re: Mutable reference to a structure field"
- Reply: Marco Baringer: "Re: Mutable reference to a structure field"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 19 Jun 2004 10:37:45 +1100
Hi,
Is there any way to get some kind of mutable reference to a field in a
structure? Something like this:
(defstruct foo field)
(defvar foo-instance (make-foo))
(setf (foo-field foo-instance) 1)
(defvar ref (get-reference-to-struct-field foo field-1))
(setf (deref ref) 2)
(foo-field foo-instance) => 2
So far, all I can think of is using a closure:
(defvar foo-instance (make-foo))
(setf (foo-field foo-instance) 1)
(defvar ref (lambda (x) (setf (foo-field foo-instance) x)))
(funcall ref 2)
(foo-field foo-instance) => 2
This works OK, but in the program I'm working on the number of
references could get quite large, and (I assume that) every closure
created pushes some stuff onto the stack.
In case I'm barking up the wrong tree altogether, this is my actual
problem. I'm traversing a parse tree, simulating recursion by looping
and pushing nodes in the tree onto a stack. Most of the nodes in the
tree I want to leave alone, but there are a few I want to modify. This
would be much easier if there was some way to modify a node without
knowing what its parent node is. (The nodes in the tree are represented
as structures.)
Thanks,
Alex
- Next message: Brian Downing: "Re: Mutable reference to a structure field"
- Previous message: Duane Rettig: "Re: Was not making tail recursion elmination a mistake?"
- Next in thread: Brian Downing: "Re: Mutable reference to a structure field"
- Reply: Brian Downing: "Re: Mutable reference to a structure field"
- Reply: Barry Margolin: "Re: Mutable reference to a structure field"
- Reply: Marco Baringer: "Re: Mutable reference to a structure field"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]