[racket-dev] Optional equality predicate for assoc and member

From: Eli Barzilay (eli at barzilay.org)
Date: Fri Apr 22 17:09:51 EDT 2011

30 minutes ago, Matthias Felleisen wrote:
> This is way overdue. Thanks. 


40 minutes ago, Vincent St-Amour wrote:
> With this patch, assoc and member are implemented in Racket. They
> are currently implemented in C. I haven't measured the performance
> impact of the change, but I can do it if someone believes it's
> necessary.

One way to make it fast is to have it bound to a macro so (member f l
eq?) expands to a `memq', and when used as a function have it dispatch
to `memq' if given `eq?'.  Then, if the racket version is fast enough,
then you can do something similar to what `sort' does -- implement it
with a macro that generates the body, use the macro a few times to get
compiled versions of the function with `eq?' etc hard wired (and
therefore inlined), and then do the same kind of dispatch over the
results.  One benefit of that is that you can use additional common
cases like `='.  The implementation of `sort' does this with one more
trick that Matthew suggested: have the macro that generates the code
be local, so that there's no need to keep it in the compiled file.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the dev mailing list.