guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Issue with compiling to scheme


From: mark . d . witmer
Subject: Re: Issue with compiling to scheme
Date: Sat, 03 Aug 2013 13:12:48 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

address@hidden 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]