From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: mark.d.witmer@gmail.com Newsgroups: gmane.lisp.guile.user Subject: Re: Issue with compiling to scheme Date: Sat, 03 Aug 2013 13:12:48 -0400 Message-ID: <87vc3mlmun.fsf@gmail.com> References: <874nb7evbo.fsf@markwitmer.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1375565248 31195 80.91.229.3 (3 Aug 2013 21:27:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 3 Aug 2013 21:27:28 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Aug 03 23:27:29 2013 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1V5jMH-0002kS-7Z for guile-user@m.gmane.org; Sat, 03 Aug 2013 23:27:29 +0200 Original-Received: from localhost ([::1]:41318 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V5jMG-0007YT-RK for guile-user@m.gmane.org; Sat, 03 Aug 2013 17:27:28 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43771) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V5fN9-00068r-UZ for guile-user@gnu.org; Sat, 03 Aug 2013 13:12:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V5fN4-00049F-86 for guile-user@gnu.org; Sat, 03 Aug 2013 13:12:07 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:38186) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V5fN4-00048n-1k for guile-user@gnu.org; Sat, 03 Aug 2013 13:12:02 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1V5fN2-0005G8-O4 for guile-user@gnu.org; Sat, 03 Aug 2013 19:12:00 +0200 Original-Received: from cpe-184-58-115-186.woh.res.rr.com ([184.58.115.186]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 03 Aug 2013 19:12:00 +0200 Original-Received: from mark.d.witmer by cpe-184-58-115-186.woh.res.rr.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 03 Aug 2013 19:12:00 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 44 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: cpe-184-58-115-186.woh.res.rr.com User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:jkq6ktfYdmqpZkNy7Y0KZhgQDWg= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-Mailman-Approved-At: Sat, 03 Aug 2013 17:27:21 -0400 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:10602 Archived-At: 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