unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Noah Lavine <noah.b.lavine@gmail.com>
To: guile-devel <guile-devel@gnu.org>
Subject: Modules with Circular Dependencies
Date: Fri, 18 Mar 2011 14:15:41 -0400	[thread overview]
Message-ID: <AANLkTikC-x=4WVC855GxHxxtYhXDy6Nxnw0nEEQLyNUn@mail.gmail.com> (raw)

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



             reply	other threads:[~2011-03-18 18:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-18 18:15 Noah Lavine [this message]
2011-03-18 20:45 ` Modules with Circular Dependencies Ludovic Courtès
2011-03-18 21:16   ` Noah Lavine
2011-03-24 21:50     ` Andy Wingo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='AANLkTikC-x=4WVC855GxHxxtYhXDy6Nxnw0nEEQLyNUn@mail.gmail.com' \
    --to=noah.b.lavine@gmail.com \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).