[CM] internal definitions of a macro body do not see each other (regression since 2025)
Massimiliano Gubinelli
m.gubinelli at gmail.com
Sun Oct 4 18:18:21 PDT 2026
re-Hi again ,
A second one, about internal definitions in the body of a macro. It is
not related to my previous report: the patch I sent does not change it,
and the macro runs only once.
(define-macro (m . args)
(define (one l) (car l))
(define (both k) (list (one k) (one k)))
`(quote ,(both args)))
(display (m a b c)) (newline) ; (a a)
$ gcc -O2 -DWITH_MAIN s7.c -o s7 -lm -ldl
$ ./s7 bug2.scm
s7: 5-Oct-2026
load bug2.scm
;unbound variable one in (one k), perhaps one?
...
The same with s7 11.9 (21-Sep-2026); s7 24-Sep-2025 prints (a a).
- With a single internal definition, used in the body of m, it works.
- With the two definitions inside (let () ...) in the body of m, it
works.
- The same body in a function, (define (f . args) ...), works.
- define-macro* and a macro with named parameters behave like m.
When the definitions are made by another macro, the result is a
segfault instead of the error:
(define-macro (mdef name . params)
`(define ,name (lambda , at params)))
(define-macro (m . args)
(mdef one (l) (car l))
(mdef both (k) (list (one k) (one k)))
`(quote ,(both args)))
(display (m a b c)) (newline) ; (a a) in s7 24-Sep-2025
$ ./s7 bug2b.scm; echo "exit status $?"
s7: 5-Oct-2026
load bug2b.scm
Segmentation fault: 11
exit status 139
With -DS7_DEBUGGING=1 that one stops with
s_lookup_1[...]: k unbound
symbol_id: 43, let_id: 44, symbol? (type: 10), opt_op: 0 unopt, ...
so there the parameter k of both is not found when both runs.
We met it in TeXmacs with the case-lambda of Guile 1.6, whose helpers
are internal definitions of the macro body: calling a case-lambda raised
"unbound variable alength", or crashed. We moved those helpers out of the
macro.
Max
(macOS 15.7.1, Apple clang)
More information about the Cmdist
mailing list