On Thu, May 1, 2025 at 10:21 PM David Scherfgen via Maxima-discuss < maxima-disc...@lists.sourceforge.net> wrote:
> Hello, > > I noticed that GCL 2.7.1 compiles these functions differently: > > (defun f (x) (member x '(a b c))) > (defun g (x) (member x '(a b c) :test #'eq)) > > I suppose that's because F uses the default EQL as the test. I tried to > understand the C code it generated, but it was incomprehensible to me. > Anyways, I saw that the second function, G, had inlined the MEMBER call > into (OR (EQ X 'A) (EQ X 'B) (EQ Y 'C)), which is reasonable. But why does > F get compiled differently? > > Shouldn't the compiler notice that the second argument to MEMBER is a > literal list of symbols and automatically use EQ instead of the default EQL > test? That would be an easy and safe optimization. > > The same goes for the case where the first argument to MEMBER is a literal > symbol. > > Maxima is full of such instances where MEMBER is used as a shorter way to > write (OR (EQ ...) (EQ ...) ...), and ":test #'eq" has mostly been removed > because it was believed that any modern Lisp compiler would apply this > optimization automatically. At least SBCL does. (CCL doesn't, I have filed > a report already.) > Does it really matter that this conversion isn't done? Another reason why we should have left memq around. Then we could have written a compiler macro to do the optimization we want. Assuming it really makes a difference.