This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Scheme style auto-resizing hashtable (fwd)



telford@eng.uts.edu.au writes:
> > > For that matter, one could make up similar arguments against
> > > insert!/lookup/remove!, e.g.: 
> > > 
> > > * insert! implies adding a new element, but it might in fact be
> > > changing an existing element. set! expresses this much better
> > 
> > okay.
> 
> But in guile, set! will not create a new variable,
> you need define! to do that...
> 
> Similarly, vector-set! will not exend the length of a vector to
> contain an extra element, you get an out of range error if you try.
> 
> Thus, set! implies not that you may be changing an existing element
> but that you MUST be changing an existing element. I would say that
> using a similar name for a subtly different idea is worse than using
> a different name altogether. Probably ``lookup'' should be changed to
> ``ref'', but even in this case, should it be an error to ref something
> that doesn't exist or should it return #f? For my work, returning
> #f is far more useful than throwing exceptions since I'm can use
> a (cond) to scan several options.
> 

If a hashtable returns #f for any key that has no value, then all keys
implicitly exist and `hash-table-set!' is perfectly parallel to
`vector-set!' in mutating only slots that (logically) exist.

 - Maciej