Very puzzling! I think you're doing the update correctly:
> (hash-ref (hashtainer-contents (hash-ref (hashtainer-contents
the-hashtainer) 'layer-1)) 'layer-2)
"hello from layer 2"
But here's the trouble:
> (eq? (hashtainer-contents the-hashtainer)
(hashtainer-contents (hash-ref (hashtainer-contents the-hashtainer)
'layer-1)))
#t
When I print the hashtainer, here's what I see:
(hashtainer #0=(hash 'layer-1 (hashtainer #0#) 'layer-2 "hello from layer
2"))
And I think this is Racket's way of printing cyclic data.
If we could make sure the #:auto-value is evaluated for each new struct
things would be good.
I'm not sure how to do that, but here's a work-around:
(struct hashtainer (contents) #:transparent)
(define (make-hashtainer) (hashtainer (make-hash)))
;; .... then use (make-hashtainer) instead.
;; You can also (provide (rename-out [make-hashtainer hashtainer]))
;; to other modules
On Wed, Feb 24, 2016 at 12:45 AM, Gavin McGimpsey <[email protected]> wrote:
> I've been puzzling over this all evening – hoping someone can clarify
> what's going on.
>
> Here's a complete minimal example:
> https://gist.github.com/gavinmcgimpsey/05bfe26f039944f23a9c
>
> I think my question is: what's the proper way to update nested data like
> this?
>
> Gavin
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.