On Mon, 14 Sep 2020 at 14:18, Hendrik Boom <hend...@topoi.pooq.com> wrote:

> I would, ideally, only use hashcons on those cons-cells which had
> themselves
> been hashconsed, so eq? would suffice.
>

The challenge is checking to see whether a new allocation is required.
Checking `eq?` of the cdr suffices, but seldom is `eq?` appropriate for the
car, assuming you want `(eq? (hashcons (set) '()) (hashcons (set) '()))`
and similar to hold. Canonicalize looks, roughly, like

(define (canonicalize c)
  (match c
    [(cons a d) (if (cell-exists-in-weak-table-with-car-and-cdr? a d) ;; (X)
                    (extract-and-return-existing-cell a d)
                    (intern-and-return-cons-of a (canonicalize d)))]
    [_ c]))

The line marked (X) will usually want to compare `a` with `equal?` and `d`
with `eq?`.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAM8fPiS0moqzAfDUdtH5aBx337Mt-TrWQkZ8EQro5HHWJtkEKg%40mail.gmail.com.

Reply via email to