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

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



On 05/25/2013 09:45 AM, Per Bothner wrote:
> A 'comparator' data type might be still be worth considering.
> I could work well with a small library of utility routines.
> For example (ascending PROJ) and (descending PROJ) take a one-argument
> "projection" function that is applied to the elements to be
> compared.  Another useful utility (useful for sorting)
> takes a list of comparators, where the first element is
> the primary key, the second the secondary key, etc.
>
> Anyway, this is all very hand-wavy ...

Another idea, focusing for now just on equivalance functions:
If the language supports 'procedure properties' then one
way to "bundle" an equivalance function with a hash function
is to make the latter a property of the former.  For example,
using Kawa's syntax:

http://www.gnu.org/software/kawa/Procedure-properties.html

One could define:

(define-procedure my-eq?
    equivalence-hash: (lambda (obj) (whatever-hash ... obj))
    (lambda (obj1 obj2) (whatever-eq ... obj1 obj2))

Then as user can do:

   (make-hash-table my-eq?)

and the implementation can extract the hash function as:
   (procedure-property equivalence 'equivalence-hash)
-- 
	--Per Bothner
per@x   http://per.bothner.com/

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