* Modules with Circular Dependencies
@ 2011-03-18 18:15 Noah Lavine
2011-03-18 20:45 ` Ludovic Courtès
0 siblings, 1 reply; 4+ messages in thread
From: Noah Lavine @ 2011-03-18 18:15 UTC (permalink / raw)
To: guile-devel
Hello all,
I recently ran up against an issue about modules with circular
dependencies while working on PEG stuff. I reduced it to the following
test case.
Here is file "test-a.scm":
(define-module (test-a)
#:use-module (test-b))
(define-syntax hello
(syntax-rules ()
((hello) "Hello, world!\n")))
And here is "test-b.scm":
(define-module (test-b)
#:use-module (test-a))
(display (hello))
As you can see, test-a and test-b have a circular dependency in which
test-a defines syntax that test-b uses.
If I run "guile -L "." -s test-a.scm", I get the error
;;; WARNING: compilation of /Users/noah/Desktop/guile/guile/test-a.scm failed:
;;; key unbound-variable, throw_args ("module-lookup" "Unbound
variable: ~S" (hello) #f)
Clearly the order of compilation is a problem. So I tried this
modified test-a.scm:
(define-module (test-a))
(define-syntax hello
(syntax-rules ()
((hello) "Hello, world!\n")))
(use-modules (test-b))
I moved the reference to test-b to the end, but got the same error.
So clearly the module system doesn't like circular dependencies on
syntax. I think it probably should understand them. I have a feeling
that they don't end up adding complexity to compilation, even though
it seems like they would, because in order to compile a module you
have to search its dependencies for syntax definitions anyway.
However, either way, I don't think this issue is documented in the
manual.
So what do you all think should happen in this case?
Noah
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Modules with Circular Dependencies
2011-03-18 18:15 Modules with Circular Dependencies Noah Lavine
@ 2011-03-18 20:45 ` Ludovic Courtès
2011-03-18 21:16 ` Noah Lavine
0 siblings, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2011-03-18 20:45 UTC (permalink / raw)
To: guile-devel
Hello!
The problem is that modules are resolved at compile-time, in addition to
run-time, so there just can’t be circular dependencies.
Besides, I think it’s generally a problem from an engineering viewpoint
when cycles are introduced.
So my feeling is that Guile should be able to detect cycles and warn
users.
Thanks,
Ludo’.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Modules with Circular Dependencies
2011-03-18 20:45 ` Ludovic Courtès
@ 2011-03-18 21:16 ` Noah Lavine
2011-03-24 21:50 ` Andy Wingo
0 siblings, 1 reply; 4+ messages in thread
From: Noah Lavine @ 2011-03-18 21:16 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: guile-devel
Hello,
> The problem is that modules are resolved at compile-time, in addition to
> run-time, so there just can’t be circular dependencies.
It's true that a module couldn't depend, at compile-time, on a module
that was only available at run-time. However, I think we could handle
circular dependencies as long as all of the modules involved were
available at compile-time. I would even say that this is one more
instance of the general principle that people shouldn't have to do
things that computers are able to do for them - in this case, you
shouldn't have to manually order your syntax definitions and uses when
your computer can do a graph search for you.
> Besides, I think it’s generally a problem from an engineering viewpoint
> when cycles are introduced.
This sounds like it could be true, but it's so general I don't know
how to respond. Could you talk more about it, or give an example?
> So my feeling is that Guile should be able to detect cycles and warn
> users.
Yes, at a minimum cycle detection would be good.
Noah
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Modules with Circular Dependencies
2011-03-18 21:16 ` Noah Lavine
@ 2011-03-24 21:50 ` Andy Wingo
0 siblings, 0 replies; 4+ messages in thread
From: Andy Wingo @ 2011-03-24 21:50 UTC (permalink / raw)
To: Noah Lavine; +Cc: Ludovic Courtès, guile-devel
On Fri 18 Mar 2011 22:16, Noah Lavine <noah.b.lavine@gmail.com> writes:
>> The problem is that modules are resolved at compile-time, in addition to
>> run-time, so there just can’t be circular dependencies.
>
> It's true that a module couldn't depend, at compile-time, on a module
> that was only available at run-time. However, I think we could handle
> circular dependencies as long as all of the modules involved were
> available at compile-time. I would even say that this is one more
> instance of the general principle that people shouldn't have to do
> things that computers are able to do for them - in this case, you
> shouldn't have to manually order your syntax definitions and uses when
> your computer can do a graph search for you.
While I'm sympathetic to the sentiment here, the case you present (and
the PEG case; about which more tomorrow) is as Ludovic described it:
modules depending on each other at compile-time. `define-module' and
`use-modules' resolve their interfaces both at expand-time and at
run-time.
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-03-24 21:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-18 18:15 Modules with Circular Dependencies Noah Lavine
2011-03-18 20:45 ` Ludovic Courtès
2011-03-18 21:16 ` Noah Lavine
2011-03-24 21:50 ` Andy Wingo
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).