[cdr-discuss] Order of arguments in hashref

Ingvar ingvar at hexapodia.net
Thu Nov 23 06:30:39 UTC 2006


Chris writes:
> Thanks for putting together the genhash proposal.  It's a much needed
> extension to CL hash tables!
> 
> I might be coming late to the discussion of genhash, so I'll start
> with a simple question:
> 
> Why is the order of arguments in HASHREF first the key then the table
> rather that the table and then the key?  Here is how it is now:
> 
>   (hashref key table &optional (default nil)) 

Because that's the way GETHASH has them. This way, changing code from using 
one to the other is a trivial search & replace. I was waffling back and forth 
when I wrote the genhash library initially, but the deciding factor was when I 
started getting errors both for HASHREF and GETHASH, not being able to keep 
the two completely straight. That tipped the balance towards "keep things as 
they are".

> It has always bothered me that CL:GETHASH, CL:REMHASH, and CL:NTH have
> the accessor (in this case the key and the index) as the first arg
> while AREF, SVREF, CHAR, SCHAR, and ELT have the the container as the
> first arg (in this case the array, vector, string, and sequence).
> 
> I think the answer to my question might be that HASHREF is consistent
> with the calling order in GETHASH.  

Indeed, that is the case.
 
> My preference is to have the ordering be table and then key and be
> consistent with ELT et.al. 

//Ingvar




More information about the cdr-discuss mailing list