Closed GoogleCodeExporter closed 8 years ago
Thinking about how to build weakdicts on top of these, I think it'd be
efficient if a weakref had a strongly held "note" field as well as its weakly
held "value" field. (Python implements their weakdicts this way. It saves
creating a different sentry closure for each key,value pair in the weakdict.
Just one generic sentry closure can be used, which makes use of the weakref's
"note" field. Python calls this field "key".) So the signature might look like
this:
let r = weak_ref value note; // just set note to () if you don't want it
get r; // returns {} or {value}
get_note r; // always returns the original note
No put function needed or wanted.
Original comment by dubious...@gmail.com
on 20 Jun 2012 at 1:30
Actually, this would be better:
let r = weak_ref value note sentry; // just use () for note if you don't want it
// and use void for sentry if you don't want it
// we ask for the sentry during construction, because we provide the following guarantee:
let r2 = weak_ref value2 note2 sentry2;
// now r === r2 (and they also hash the same) just in case (original) value === (original) value2 && note === note2 && sentry === sentry2
// and we can determine that r === r2 even after value has been collected
get r; // as before
get_note r; // as before
get_sentry r; // returns the sentry originally supplied
Original comment by dubious...@gmail.com
on 20 Jun 2012 at 2:05
Alas, I don't see how the expression references we have in the primitives
module could be made to support any of the desired behaviours that you propose
here.
My idea was to simply add a weak_ref function which would create a reference
like ref, but not actually count a reference to the pointee. But that doesn't
really work either. The idea was to use that in cyclic things like:
let x = ref ();
let y = weak_ref (2,x);
put x (1,y);
Unfortunately, the weak reference on (2,x) doesn't solve the problem, y itself
would have to be a weak reference, and I'm afraid that this just doesn't work
without special support from the runtime system.
Sorry, my bad. I guess we have to go back to the drawing board. The simple
solution that I was hoping for doesn't exist.
Original comment by aggraef@gmail.com
on 20 Jun 2012 at 4:34
Original comment by aggraef@gmail.com
on 20 Jun 2012 at 4:35
I think I see how to do it with the materials already in the C API. I'll let
you know.
Original comment by dubious...@gmail.com
on 21 Jun 2012 at 8:25
OK, this can be marked as closed (if you like my solution). It does need robust
testing though.
Original comment by dubious...@gmail.com
on 22 Jun 2012 at 4:23
Ok, closing the issue, as requested.
Original comment by aggraef@gmail.com
on 23 Jun 2012 at 10:04
Original issue reported on code.google.com by
dubious...@gmail.com
on 20 Jun 2012 at 2:02