unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Should an enclosing let keep the compiler from handling define-module?
@ 2019-07-24 15:27 Rob Browning
  2019-08-05 18:04 ` Mark H Weaver
  0 siblings, 1 reply; 3+ messages in thread
From: Rob Browning @ 2019-07-24 15:27 UTC (permalink / raw)
  To: guile-devel


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

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)))))))

Thanks
-- 
Rob Browning
rlb @defaultvalue.org and @debian.org
GPG as of 2011-07-10 E6A9 DA3C C9FD 1FF8 C676 D2C4 C0F0 39E9 ED1B 597A
GPG as of 2002-11-03 14DD 432F AE39 534D B592 F9A0 25C8 D377 8C7E 73A4



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Should an enclosing let keep the compiler from handling define-module?
  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
  2019-08-06  1:31   ` Rob Browning
  0 siblings, 1 reply; 3+ messages in thread
From: Mark H Weaver @ 2019-08-05 18:04 UTC (permalink / raw)
  To: Rob Browning; +Cc: guile-devel

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Should an enclosing let keep the compiler from handling define-module?
  2019-08-05 18:04 ` Mark H Weaver
@ 2019-08-06  1:31   ` Rob Browning
  0 siblings, 0 replies; 3+ messages in thread
From: Rob Browning @ 2019-08-06  1:31 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: guile-devel

Mark H Weaver <mhw@netris.org> writes:

> 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?

Or one that's "sufficiently similar".

I think in part I was originally confused because I didn't understand
say --language very well (or what changing the language actually
affected), and in the end I realized (I think) that it's a fairly blunt
instrument with fairly broad effects, and so I reworked what I was doing
to never explicitly change the current language, i.e. to rely on compile
#:from #:to and load-compiled-file, etc.

So if this doesn't seem like any real issue as far as Guile is concerned
right now, feel free to disregard.

And thanks for the response.
-- 
Rob Browning
rlb @defaultvalue.org and @debian.org
GPG as of 2011-07-10 E6A9 DA3C C9FD 1FF8 C676 D2C4 C0F0 39E9 ED1B 597A
GPG as of 2002-11-03 14DD 432F AE39 534D B592 F9A0 25C8 D377 8C7E 73A4



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-08-06  1:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2019-08-06  1:31   ` Rob Browning

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).