From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.user Subject: Re: Me no understand scoping Date: Sat, 09 Aug 2008 13:05:58 +0200 Message-ID: References: <87r69ccaus.fsf@unknownlamer.org> <489074A9.1080508@wilsonjc.us> <49dd78620807310020i8b55067gd22f6ce361a04d7d@mail.gmail.com> <49dd78620807311437g7ab367bdxed293a3b8dbd5753@mail.gmail.com> <49dd78620808021043h66f6d953uff37c35d018afb80@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1218288546 18648 80.91.229.12 (9 Aug 2008 13:29:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 9 Aug 2008 13:29:06 +0000 (UTC) Cc: guile-user@gnu.org To: "Maciek Godek" Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Aug 09 15:29:57 2008 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KRoW2-0001lZ-EI for guile-user@m.gmane.org; Sat, 09 Aug 2008 15:29:54 +0200 Original-Received: from localhost ([127.0.0.1]:53414 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KRoV6-0000z0-LZ for guile-user@m.gmane.org; Sat, 09 Aug 2008 09:28:56 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KRoU8-00005W-Eh for guile-user@gnu.org; Sat, 09 Aug 2008 09:27:56 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KRoU3-0008Sh-82 for guile-user@gnu.org; Sat, 09 Aug 2008 09:27:55 -0400 Original-Received: from [199.232.76.173] (port=38752 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KRoU2-0008SH-Vs for guile-user@gnu.org; Sat, 09 Aug 2008 09:27:51 -0400 Original-Received: from a-sasl-fastnet.sasl.smtp.pobox.com ([207.106.133.19]:41923 helo=sasl.smtp.pobox.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KRoU2-00026Y-96 for guile-user@gnu.org; Sat, 09 Aug 2008 09:27:50 -0400 Original-Received: from localhost.localdomain (localhost [127.0.0.1]) by a-sasl-fastnet.sasl.smtp.pobox.com (Postfix) with ESMTP id DDCCA52721; Sat, 9 Aug 2008 09:27:46 -0400 (EDT) Original-Received: from unquote (239.Red-88-0-165.dynamicIP.rima-tde.net [88.0.165.239]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-sasl-fastnet.sasl.smtp.pobox.com (Postfix) with ESMTPSA id E86AF52720; Sat, 9 Aug 2008 09:27:44 -0400 (EDT) In-Reply-To: (Maciek Godek's message of "Sat, 2 Aug 2008 23:36:24 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-Pobox-Relay-ID: F488F6BC-6616-11DD-90FA-CE28B26B55AE-02397024!a-sasl-fastnet.pobox.com X-detected-kernel: by monty-python.gnu.org: Solaris 10 (beta) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:6732 Archived-At: Hi Maciek, On Sat 02 Aug 2008 23:36, "Maciek Godek" writes: > [Neil] >> 1. IMO this could be really beautifully done in GOOPS, by defining >> custom metaclasses and slot types. > > I've been considering that, and I'm still having doubts. > The main reason is that there's no documented way > of accessing GOOPS objects from C (except from using > scm_c_eval_string etc.), or at least I couldn't find any > documentation for that. You can use scm_slot_ref et al. See goops.h. > Besides (which is the matter of personal taste), I don't > like the idea of using generics and trashing the global > namespace with them. (I mean, the sole idea of generics > is fine, but I wouldn't want to be forced to use them) [...] > I'm really trying to get close > to the classical OOP notation: object.method() -- and > it's probably why I explore the potential of using these > "poor man's objects" I wrote about this notational issue a while back on my blog, http://wingolog.org/; I'm offline at the moment, so unfortunately I don't have a link. Search for "slot-ref". I think with-accessors is an elegant solution to this problem. > But the point is that I saw that there is a 'make-hash-table' function > available in lisp -- and this lead me to the conclusion that it's probably > because the scopes/closures/environments implicitly use hash > tables to store their bindings (and the same mechanism was given > explicitly to the programmer). This is false. Consider the closure: (let ((val 0)) (lambda () (set! val (1+ val)) val)) Lexical scoping + closures was one of the fundamental ideas of scheme. You can analyze this code /lexically/ to determine that we only need to allocate storage for one variable. Wherever you see `val' in the body of the lambda, you know /lexically/ that you are referring to a location that is one step out in the stack frame, and the 0th location in that frame, the frame created by `let'. So there is no need to store the name, "val", at all! By way of illustration, look at this disassembly of that closure in guile-vm: scheme@(guile-user)> (let ((val 0)) (lambda () (set! val (1+ val)) val)) $1 = # scheme@(guile-user)> ,x $1 Disassembly of #: nargs = 0 nrest = 0 nlocs = 0 nexts = 0 Bytecode: 0 (late-variable-ref 0) 2 (external-ref 0) 4 (call 1) 6 (external-set 0) 8 (external-ref 0) 10 (return) Objects: 0 ((guile-user) . 1+) Externals: 0 0 Sources: 6 #(1 36 #f) 8 #(1 26 #f) The external shown there, "0 0" refers exactly to the outer stack frame, the zeroeth location. The external-ref and external-set instructions manipulate that storage location /by index and not by name/. Do you see now why local-eval can't possibly work in the presence of efficient compilation? Scheme does not give you the particular kind of dynamism that you want. There is no hash table lurking inside a closure. On the other hand, modules do have hash tables, and modules are evaluation environments; and they have been treated in some literature as closures. Perhaps consider using modules as your first-class objects? > And so I never stopped to believe that (define x 5) is more or > less equivalent to (hash-set! global-scope 'x 5). At the top level it is; but s/global-scope/the current module/. But internal defines are completely different. Happy hacking, Andy -- http://wingolog.org/