* bug#73984: Compiler/interpreter doesn't handle the macro defined after it's used
@ 2024-10-24 12:45 Artyom Bologov
2024-10-24 14:49 ` Thompson, David
0 siblings, 1 reply; 3+ messages in thread
From: Artyom Bologov @ 2024-10-24 12:45 UTC (permalink / raw)
To: 73984
[-- Attachment #1: Type: text/plain, Size: 1096 bytes --]
Hello y'all,
So I'm working on a project with a moderate amount of macros and some
tangled code paths. Which often means I have non-linear and
hard-to-figure-out inter-dependencies between pieces of code. One of
them bit me today: a macro that was defined after a procedure it was
used in, resulted in an "Unbound variable" error when the procedure was
called. The procedure was called long after the macro was finally
defined, so it shouldn't have been a problem. Find the test file
attached and use it as:
```
GUILE_LOAD_PATH=.:$GUILE_LOAD_PATH guile
scheme@(guile-user)> (use-modules (test))
;;; note: source file ./test.scm
;;; newer than compiled /.../test.scm.go
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;; or pass the --no-auto-compile argument to disable.
;;; compiling ./test.scm
;;; test.scm:7:5: warning: possibly unbound variable `a'
;;; test.scm:8:5: warning: possibly unbound variable `b'
;;; compiled /.../test.scm.go
scheme@(guile-user)> (testing)
;; ice-9/boot-9.scm:1685:16: In procedure raise-exception:
;; Unbound variable: a
;; ...
```
[-- Attachment #2: Scheme file to test forward definition problem --]
[-- Type: text/plain, Size: 268 bytes --]
(define-module (test)
#:export-syntax (with-something)
#:export (testing))
(define (testing)
(with-something
((a 1)
(b a))
'hello))
(define-syntax-rule (with-something ((var init) ...) body ...)
(let* ((var init) ...)
(begin body ...)
#t))
[-- Attachment #3: Type: text/plain, Size: 271 bytes --]
The expected behavior is that both "a" and "b" are defined and macro
expanded during compilation, regardless of whether it was defined before
or after use.
I'm not sure if that's a valid bug, but here you go anyway.
Best of love,
--
Artyom Bologov
https://aartaka.me
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#73984: Compiler/interpreter doesn't handle the macro defined after it's used
2024-10-24 12:45 bug#73984: Compiler/interpreter doesn't handle the macro defined after it's used Artyom Bologov
@ 2024-10-24 14:49 ` Thompson, David
2024-10-24 15:13 ` Artyom Bologov
0 siblings, 1 reply; 3+ messages in thread
From: Thompson, David @ 2024-10-24 14:49 UTC (permalink / raw)
To: Artyom Bologov; +Cc: 73984
Hi Artyom,
On Thu, Oct 24, 2024 at 8:47 AM Artyom Bologov <mail@aartaka.me> wrote:
>
> Hello y'all,
>
> So I'm working on a project with a moderate amount of macros and some
> tangled code paths. Which often means I have non-linear and
> hard-to-figure-out inter-dependencies between pieces of code. One of
> them bit me today: a macro that was defined after a procedure it was
> used in, resulted in an "Unbound variable" error when the procedure was
> called. The procedure was called long after the macro was finally
> defined, so it shouldn't have been a problem.
I don't think this is a bug. In my experience, macro definitions must
precede uses.
- Dave
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#73984: Compiler/interpreter doesn't handle the macro defined after it's used
2024-10-24 14:49 ` Thompson, David
@ 2024-10-24 15:13 ` Artyom Bologov
0 siblings, 0 replies; 3+ messages in thread
From: Artyom Bologov @ 2024-10-24 15:13 UTC (permalink / raw)
To: Thompson, David; +Cc: 73984
Hi David,
> I don't think this is a bug. In my experience, macro definitions must
> precede uses.
This is a sane answer too!
Thanks,
--
Artyom Bologov
https://aartaka.me
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-24 15:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-24 12:45 bug#73984: Compiler/interpreter doesn't handle the macro defined after it's used Artyom Bologov
2024-10-24 14:49 ` Thompson, David
2024-10-24 15:13 ` Artyom Bologov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).