(MEMBER ...) with literal symbol(s)

David Scherfgen via Maxima-discuss <[email protected]> Fri, 2 May 2025 07:14:11 +0200
Newsgroups gmane.comp.mathematics.maxima.general,gmane.lisp.gcl.devel
Message-ID <CAMTHLKgh=hrHpfgobRM=_CmcfohENBwaQvqgvOPqvV6vs=ygnw@mail.gmail.com>
--===============3515685217032289293==
Content-Type: multipart/alternative; boundary="00000000000031bf4706342039e4"

--00000000000031bf4706342039e4
Content-Type: text/plain; charset="UTF-8"

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.)

Best regards
David Scherfgen

--00000000000031bf4706342039e4
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto">Hello,<div dir=3D"auto"><br></div><div dir=3D"auto">I not=
iced that GCL 2.7.1 compiles these functions differently:</div><div dir=3D"=
auto"><br></div><div dir=3D"auto">(defun f (x) (member x &#39;(a b c)))</di=
v><div dir=3D"auto">(defun g (x) (member x &#39;(a b c) :test #&#39;eq))</d=
iv><div dir=3D"auto"><br></div><div dir=3D"auto">I suppose that&#39;s becau=
se 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 secon=
d function, G, had inlined the MEMBER call into (OR (EQ X &#39;A) (EQ X &#3=
9;B) (EQ Y &#39;C)), which is reasonable. But why does F get compiled diffe=
rently?</div><div dir=3D"auto"><br></div><div dir=3D"auto">Shouldn&#39;t th=
e compiler notice that the second argument to MEMBER is a literal list of s=
ymbols and automatically use EQ instead of the default EQL test? That would=
 be an easy and safe optimization.</div><div dir=3D"auto"><br></div><div di=
r=3D"auto">The same goes for the case where the first argument to MEMBER is=
 a literal symbol.</div><div dir=3D"auto"><br></div><div dir=3D"auto">Maxim=
a is full of such instances where MEMBER is used as a shorter way to write =
(OR (EQ ...) (EQ ...) ...), and &quot;:test #&#39;eq&quot; has mostly been =
removed because it was believed that any modern Lisp compiler would apply t=
his optimization automatically. At least SBCL does. (CCL doesn&#39;t, I hav=
e filed a report already.)</div><div dir=3D"auto"><br></div><div dir=3D"aut=
o">Best regards</div><div dir=3D"auto">David Scherfgen</div></div>

--00000000000031bf4706342039e4--


--===============3515685217032289293==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============3515685217032289293==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Maxima-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/maxima-discuss

--===============3515685217032289293==--