[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: hash tables
Re: hash tables
30 Jun 2001 13:36:01 -0400
Gnus/5.09 (Gnus v5.9.0) Emacs/21.0.103
>>>>> "Thomas" == Thomas Bushnell, BSG <address@hidden> writes:
Thomas> Python does not have improper lists. So I'm going to use
Thomas> pairs like ('hash . the-table-itself) to represent Python
Thomas> objects that don't have easy Scheme counterparts. That
Thomas> works as long as the cdr of these pairs is never itself a
Thomas> pair; then it's easy and quick to distinguish these from
Thomas> Python lists.
Python also does not have symbols (probably Guile's greatest boon in
writing translators :-), so you could also check if the car is a
symbol. Then you can fit additional information in the list, like
('hash table size elements), without having to go through an extra
level of indirection to look them up.
>> Another approach, which more closely matches Python's
>> dictionaries, is to define a hash record (or class), and give
>> it some meta-information. Such as the ahash
>> (automatically-resizing hash):
>> (make-record-type "ahash" ' (table size elements))
>> which could keep track of the current size and number of
>> elements in the table and perform a re-hash when the ratio
>> reaches a certain limit. The Perl version of this might also
>> include a next slot, holding a continuation referencing a
>> hash-fold loop for use in Perl's each.
Thomas> So far I've been avoiding records as being non-standard
Thomas> Scheme. Is that foolishness?
Non-standard but trivial to implement. After all, what you're doing
with the improper lists for Python objects is basically your own
simplified record type. It might make more sense to use the builtin
record type and if people want to port this to Schemes without records
just refer them to SRFI-9. The only catch is if they use a
vector-based implementation of records (Guile's records are
primitive), then python:tuple? has to check and return #f if the
vector is also a record.
Hmmm... speaking of SRFI's, why isn't there one on hashes?
Alex Shinn <address@hidden>
Lisper, Smalltalker, and all around poor speaker