unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: Rob Browning <rlb@defaultvalue.org>
Cc: guile-devel@gnu.org
Subject: Re: Should an enclosing let keep the compiler from handling define-module?
Date: Mon, 05 Aug 2019 14:04:04 -0400	[thread overview]
Message-ID: <87tvav8p5c.fsf@netris.org> (raw)
In-Reply-To: <875znrmp0p.fsf@trouble.defaultvalue.org> (Rob Browning's message of "Wed, 24 Jul 2019 10:27:18 -0500")

Hi Rob,

Rob Browning <rlb@defaultvalue.org> writes:

> This doesn't work with 2.2.4:
>
>   (eval-when (expand load eval)
>     (let ((ignored #t))
>       (define-module (bar)
>         #:use-module (has-foo))
>       (format #t "foo: ~s\n" (foo))))
>
> producing:
>
>   ERROR: In procedure %resolve-variable:
>   Unbound variable: foo

'define-module' should only be used at top-level.  Ideally, we should
report a clearer error when it's used elsewhere.

> Is that expected?  I'm not sure if what I was attempting is reasonable,
> but the original motivation was wanting to create a syntax that can
> capture and restore some state around the invocation of define-module,
> e.g.:
>
>   (define-syntax def-mod
>     (lambda (x)
>       (syntax-case x ()
>         ((_ name)
>          #`(eval-when (expand load eval)
>              (let ((orig (current-language)))
>                (current-language 'scheme)
>                (define-module name
>                  #:use-module (has-foo))
>                ...
>                (current-language orig)))))))

It seems misguided to try to use Scheme code to temporarily switch the
current language to Scheme.  Doesn't this approach presuppose that
Scheme is already the current language?

To be honest, I'm not yet very familiar with how the 'current-language'
parameter can be used, but from a quick search of the source, it seems
clear that the finest granularity that it can possibly be expected to
work on is that of a single top-level form.

Can you help me understand what you are trying to accomplish here?

      Thanks,
        Mark



  reply	other threads:[~2019-08-05 18:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-24 15:27 Should an enclosing let keep the compiler from handling define-module? Rob Browning
2019-08-05 18:04 ` Mark H Weaver [this message]
2019-08-06  1:31   ` Rob Browning

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=87tvav8p5c.fsf@netris.org \
    --to=mhw@netris.org \
    --cc=guile-devel@gnu.org \
    --cc=rlb@defaultvalue.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).