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

Re: SRFI 69 update

This page is part of the web mail archives of SRFI 69 from before July 7th, 2015. The new archives for SRFI 69 contain all messages, not just those from before July 7th, 2015.

It was mentioned here once before (by David Van Horn) that
"hash-table-ref/default hash-table key default -> value"
is not "equivalent to"
(hash-table-ref hash-table key (lambda () default)).

This could perhaps be written in terms of an actual definition of
hash-table-ref/default, since the current language is ambiguous:

[proposed text]
  Procedure: hash-table-ref/default hash-table key default -> value

  Behaves as if defined by
  (define (hash-table-ref/default ht key default-value)
    (hash-table-ref ht key (lambda () default-value)))
[end proposed text]

That clears up any confusion about whether "default" is a variable or a
metavariable :-)

A similar definition could be used for hash-table-update!/default, as
well - and the code snippet in "hash-table-update!" could be replaced by
a full definition, too, to make the roles of the identifiers crystal clear:

[proposed text]
  Procedure: hash-table-update! hash-table key function [ thunk ]
             -> undefined

  Semantically equivalent to, but may be implemented more
  efficiently than, the following code:

  (define (hash-table-update! ht key fn . maybe-thunk)
    (hash-table-set! ht key
                     (fn (apply hash-table-ref ht key maybe-thunk))))
[end proposed text]