Detecting whether failure-result is used by dict-ref using chaperones?

27 views
Skip to first unread message

Alex Knauth

unread,
May 21, 2020, 11:56:22 AM5/21/20
to Racket Users
Hello,

I'm working on a version of `dict/c` with chaperones, but I'm running into a surprising problem that only comes up because of the `failure-result` optional-argument to `dict-ref`.

When the `failure-result` is used, I don't want the "value" contract to apply to that result. But when the failure-result isn't used, and the "value" result happens to be exactly equal to the failure-result, I do want the "value" contract to apply to it. How do I distinguish those though?

I tried to take inspiration from Carl Eastlund's `dict/c` implemented in `mischief/contract`, but it doesn't use chaperones so it is free to both add an escape continuation, and change the `failure-result` input to always be a new synthesized procedure. That way the new synthesized failure-result procedure can call the escape continuation. If I'm constrained to chaperones, I don't know how to do either of those things.

How can I detect whether the `failure-result` is used-or-not by the dict's implementation of `dict-ref`, while keeping the `failure-result` a chaperone of the original failure-result?

Alex Knauth

Matthew Flatt

unread,
May 21, 2020, 1:21:54 PM5/21/20
to Alex Knauth, Racket Users
Stepping back a little, a chaperone constructor for a datatype often
needs some inside information and cooperation from the dataype
implementation. For example, `chaperone-hash` has the property that you
want --- the filter applied to a `hash-ref` result doesn't get used if
a failure thunk produces the `hash-ref` result --- and that works
because `hash-ref` and `chaperone-hash` are implemented together.

I'm guessing that you don't have access to a dictionary implementation
because new kinds of dictionaries can be created by implementing
`gen:dict`. Maybe `dict/c` based on chaperones can only work for
dictionaries that supply additional implementation hooks by also
implementing `gen:dict-chaperone` (or something like that).
> --
> 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 racket-users...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/9612FD20-8FFB-420D-8BAD-8FF0F837
> 7AEC%40knauth.org.
Reply all
Reply to author
Forward
0 new messages