defmacro parameters named after imported bindings expand to procedures #79
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
A
defmacroparameter whose name is also exported by one of the modulesregister-macroimports (scheme,(scheme base),srfi-1,sex-macros, ortypes) resolves to the imported binding instead of the call argument. Common names such asmin,max,car,list, or+therefore become procedure objects in the expansion.Reproduction
repro.sex:sexc -m repro.sexexpandsminandmaxto the CHICKEN procedures rather than toalphaand1.0f:sexc -Cthen fails in the C writer with a misleadingbad argument typeerror while trying to emit the procedure object.Cause
sex-macros.scm:33registers each macro as:The
(import ...)is inside the lambda, and in CHICKEN an import shadows same-named lambda parameters. The macro'sminandmaxparameters are therefore shadowed before the quasiquote body is evaluated.Possible fix
Move the
(import ...)out of the macro lambda:check-macro-aritycurrently reads the argument list from(cadr (get name 'sex-macro)), so that lookup would need adjusting for the new shape.Environment
sexcmain at7315694(2026-10-29), CHICKEN 6.0.0, macOS arm64.