From: mark.d.witmer@gmail.com
To: guile-user@gnu.org
Subject: Re: Issue with compiling to scheme
Date: Sat, 03 Aug 2013 13:12:48 -0400 [thread overview]
Message-ID: <87vc3mlmun.fsf@gmail.com> (raw)
In-Reply-To: 874nb7evbo.fsf@markwitmer.com
mark@markwitmer.com writes:
> I'm running into a problem creating custom languages that compile to
> Scheme. I have an example here of a simple compiler that takes any
> Scheme expression and generates code for creating a Guile module. If I
> compile a file using this language and reference the resulting module
> from another one that's just written in normal Scheme, it works the
> first time when the normal Scheme file gets autocompiled and then fails
> subsequently when the cached compiled Scheme file is loaded, telling me
> that any reference I make to a symbol defined in (guile) from my
> compiled non-Scheme module is undefined.
>
A little more investigating helped me find the root cause of this (as
usual). It has to do with the semantics of (begin ...), which I don't
quite grok totally, but I do know they're different in the top-level
environment and elsewhere. If you call `define-module' inside of a
(begin ...) interactively (i.e. at the repl), further expressions inside
the begin all evaluate as I expect -- inside the newly defined module,
with the bindings for (guile) imported and so forth. However, if you
compile the same expression and try to use it non-interactively (i.e. in
a script), the expressions inside the begin after define-module are
evaluted in an empty module, I think.
So the solution for compiling code is to make sure that `define-module'
is in its own expression at the top of the file like it would be if you
created the file yourself. This leads to another question: do
expressions in a high-level language need to have a 1:1 correspondence
with Scheme expressions? The #:compile function of a language takes one
expression in the higher-level language and returns a single expression
in the lower-level language, so it looks that way to me.
My use case is for guile-xcb, where the root xml tag is read in as a
single expression, and it's supposed to generate Scheme code that
includes a call to define-module and then a few other expressions to set
up context within the module. I can't see a way to do that without
wrapping the whole set of expressions in `begin', but that's what
creates the problem I described above. I can hack a solution for now but
if anyone knows a clean way to do it, that'd be much appreciated.
Thanks,
--
Mark Witmer
next prev parent reply other threads:[~2013-08-03 17:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-02 19:39 Issue with compiling to scheme mark
2013-08-03 17:12 ` mark.d.witmer [this message]
2013-08-12 13:17 ` Thien-Thi Nguyen
2013-08-13 18:09 ` mark
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=87vc3mlmun.fsf@gmail.com \
--to=mark.d.witmer@gmail.com \
--cc=guile-user@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).