From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Panicz Maciej Godek Newsgroups: gmane.lisp.guile.user Subject: Re: Unbound variables used within a form Date: Sat, 13 Oct 2012 13:40:56 +0200 Message-ID: References: <87bog7exn1.fsf@tines.lan> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1350128466 15161 80.91.229.3 (13 Oct 2012 11:41:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 13 Oct 2012 11:41:06 +0000 (UTC) Cc: guile-user@gnu.org To: Mark H Weaver Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Oct 13 13:41:13 2012 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 1TN05g-0004O3-5e for guile-user@m.gmane.org; Sat, 13 Oct 2012 13:41:12 +0200 Original-Received: from localhost ([::1]:51092 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TN05Z-0000iF-DL for guile-user@m.gmane.org; Sat, 13 Oct 2012 07:41:05 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:53509) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TN05U-0000hz-Lf for guile-user@gnu.org; Sat, 13 Oct 2012 07:41:01 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TN05T-0003lQ-9Y for guile-user@gnu.org; Sat, 13 Oct 2012 07:41:00 -0400 Original-Received: from mail-ee0-f41.google.com ([74.125.83.41]:58168) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TN05S-0003lI-W0 for guile-user@gnu.org; Sat, 13 Oct 2012 07:40:59 -0400 Original-Received: by mail-ee0-f41.google.com with SMTP id c4so2660257eek.0 for ; Sat, 13 Oct 2012 04:40:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=mVsjwyGuk2HpW0+NQ7aLf0l/sp0bV1H1vPwcEkhIiyo=; b=jXjvPh4j6IWspg7M8QT+S2UTTY65YSwRhVa8/Gli2hzo7dRV5E0s7iUMzXxFiSYP+H 2/BTMHFjsdNRiKX8KKImPFnlIdWpa4rTf27VYHl5HmRF89nSoOHBmjTzU9px1x7z3uzN 5QTGkZ/GvS2HLVP3dmroZ4pAaJZJWtRm7THRdoNQFvZCiLIJGReT1Mp81w1VwWXYaijD rRSV5tjTJELoXvOnsaxdklOYIlOQN/2NMh0MBG3El0okabh3M/BiuBYBkesGkzqXHPpA cYcZDWyxtzqVZUhKL6Qy1wiKDr8Tzl/tAbc5hGYt/w/2EXFcTsxZ9B9sgW8kn1R+ubk/ 97ow== Original-Received: by 10.14.194.72 with SMTP id l48mr9955362een.9.1350128458174; Sat, 13 Oct 2012 04:40:58 -0700 (PDT) Original-Received: by 10.14.212.6 with HTTP; Sat, 13 Oct 2012 04:40:56 -0700 (PDT) In-Reply-To: <87bog7exn1.fsf@tines.lan> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.83.41 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:9617 Archived-At: 2012/10/13 Mark H Weaver : > FYI, the standard term for these are "free variables" I thought about this, but then I thought that it could cause some confusion, as any variable that isn't bound in a formula can be considered free (even the one that does not appear in the formula) -- at least that's what I recall from my course in logic. But if there's no actual ambiguity, I can use that term, of course :) >> I just wanted to ask: >> - beside lambda*, case-lambda, case-lambda*, >> are there any additional extensions that guile introduced >> atop the Report that should be taken into account in this code? > > You also need to handle 'with-fluids'. Thanks, I will take it into account :) >> - is there any simpler way to achieve the same effect, ie. >> to acquire all external symbols that are meaningful within >> a form (assuming the core semantics, that is, that all >> the macros were expanded) > > First of all, it would be much simpler if you traversed the tree-il > directly, instead of decompiling the tree-il to scheme. Take a look at > module/language/tree-il.scm and module/language/tree-il/*.scm for > details and examples of how to traverse and analyze tree-il. > > In tree-il, you wouldn't have to recognize bound variables and remove > them from the list. The macro expander already does that job, and > specifically marks each variable reference by its type: > (1) or for top-level variables, > (2) or for variables in a different module, > (3) or for non-toplevel variables, and > (4) for selected primitives. You could simply scan for > these, discarding the lexicals. Thanks a lot! I think that this is what I've been looking for. (It's horrible when the same functionality is implemented twice for the same program) > If you still prefer to work with scheme sexps, then there are some > options you can pass to the tree-il->scheme decompiler that will make > your job easier. [...] > In combination, these two options will allow you to eliminate the > following cases from your code: >> (('@@ name ...) >> '()) > > You need to handle both '@@' and '@', and you cannot simply ignore them. I just thought about a silly optimization, but I guess you're right :] (I mean, in my context it seems to work, but I see that it generally isn't the case) > Having said all this, I think that you are taking very much the wrong > approach to how to save the code in your GUI development system. Any > programming system needs to work with the *source* code, which means > "the preferred form for making changes". In Scheme, that means the > source code before *any* compilation has taken place, even macro > expansion. > > If you are working with code after macro expansion has taken place, then > you've already lost many of the key advantages of Scheme. For example, > macro expansion turns a simple record type definition into a relatively > complex set of procedure definitions, which includes internal > implementation details that may change in future versions of Guile. [...] > I would strongly encourage you to adopt a model where your development > system maintains and manipulates its own copy of the user's source code, > rather than trying to reconstruct the code from Guile's internal data > structures. That way lies madness. Actually, I am taking a hybrid approach. The above function is needed to elliminate unnecessary variables that are introduced to the lexical context on function source re-generation. The source stored in the procedure property list is left unexpanded, and therefore human-readable. The concept of the system I'm working on is still unclear, even to me -- I only have a few rough ideas. In a way it's meant to be minimal, as I don't want to devote too much time to create a big system that would be thrown to trash afterwards. My main development decision is to avoid making development decisions, or at least to put them off for as long as I can. Everything can be redesigned eventually, once the proper idea of what I am doing is found. The sollution I took has two main advantages: it (apparently) works and is interesting to implement. And speaking of madness, isn't lisp programming about coming up with clever ways to misuse a computer? ;] Thank you for a very informative response! :) M