[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme-reports] Seeking review of sets and hash tables proposals



On Sun, May 26, 2013 at 7:49 AM, Alexey Radul <axch@x> wrote:

2) Universal lookup procedure

I am fond of the following universal lookup procedure [1]:
  (hash-table-search table key
    (lambda (value update remove)
      ...)
    (lambda (insert)
      ...))

This is very nice, and it's important to provide fundamental
operations such as this which allow arbitrary ref+update logic
without requiring the hash to be recomputed.  This is not
possible in either the SRFI-69 or R6RS APIs (though an impl
may cache one or more recently hashed values).

I also think the following utility is nice, as there is no other
existing utility to use a hash-table as a cache with a single
operation:

  (hash-table-ref/cache! table key thunk)
  => (hash-table-search
      table key
      (lambda (value update remove)
        value)
      (lambda (insert)
        (let ((res (thunk)))
          (insert res)
          res)))

-- 
Alex

_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports