From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Maciek Godek" Newsgroups: gmane.lisp.guile.user Subject: Re: Closure? Date: Tue, 15 Jul 2008 00:46:57 +0200 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1216075646 7712 80.91.229.12 (14 Jul 2008 22:47:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 14 Jul 2008 22:47:26 +0000 (UTC) Cc: guile-user@gnu.org To: "Kjetil S. Matheussen" Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Jul 15 00:48:13 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 1KIWpv-0007yO-AD for guile-user@m.gmane.org; Tue, 15 Jul 2008 00:48:04 +0200 Original-Received: from localhost ([127.0.0.1]:39058 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KIWp1-0006ms-Sq for guile-user@m.gmane.org; Mon, 14 Jul 2008 18:47:07 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KIWow-0006mE-Tv for guile-user@gnu.org; Mon, 14 Jul 2008 18:47:02 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KIWov-0006lg-Bd for guile-user@gnu.org; Mon, 14 Jul 2008 18:47:01 -0400 Original-Received: from [199.232.76.173] (port=47465 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KIWov-0006lZ-9p for guile-user@gnu.org; Mon, 14 Jul 2008 18:47:01 -0400 Original-Received: from yw-out-1718.google.com ([74.125.46.157]:1194) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KIWou-0006lP-KK for guile-user@gnu.org; Mon, 14 Jul 2008 18:47:01 -0400 Original-Received: by yw-out-1718.google.com with SMTP id 9so2160134ywk.66 for ; Mon, 14 Jul 2008 15:46:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=K5KGjirA4ON/oWR23smc3Lokaw18fhrWFzmelXAG6gA=; b=waszB5VrEcPH9Ac+DLArlul8faWMe6S+4m6bl4/WV2ievMWRx7fh+I1bq5DOWkObtD DDJETH43F2aTsdmzMHneQviTCKFxc0Hl/mL/QPhvNRPBzk+L4iybTUA0Ykmsh2Q257DA rWtRQ5jKo4iJwJVMLU/CL0pvkS9KtMZVxWSAA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=B45dM3FkB7ve4jdf/9VQ9oG51kbHZY2FTp7SlKw4MGSPaZqzjv1sYpxyoup/TEa/GS Red+Dix15d/5MeRjNspOK9MAb4434JGc/gsSRy/mvF33wHgZy4HL1klreBIMRFgJehee jSS/4ve4QUPw5s5tvR/Yy4R/AvnQX2BqzsCMw= Original-Received: by 10.142.222.21 with SMTP id u21mr4398608wfg.67.1216075617252; Mon, 14 Jul 2008 15:46:57 -0700 (PDT) Original-Received: by 10.142.133.13 with HTTP; Mon, 14 Jul 2008 15:46:57 -0700 (PDT) In-Reply-To: Content-Disposition: inline X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) 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:6659 Archived-At: >> This certainly looks like trashing global namespace >> (which isn't good in the long run) and doesn't allow you >> to have object handlers (like many variables referring >> to the same object) without additional quirks. >> > > It's just an example of what local-eval can > be good for. It's an example of a _namespace > system_, and not an _OO system_. OK, sorry, I didn't understand at first. >>> But for implementing a message passing OO system, >>> it's easier to use macros and hash tables, plus >>> that it probably performs much better: >> >> Pefrorms better than local-eval or better than >> define-namespace? >> > > It's much faster than local-eval since it's not > calling eval for each method call. The overhead of calling > a method in an OO system, based on hash tables > and macros, is basically just the time it takes looking > up the address of the function from > a hash-table. For guile, which has a large > overhead already, your program probably won't > go any slower doing this compared to calling > functions directly: Is local-eval much slower than the usual eval? It is very probable that I get something wrong right now, but according to my imagination of a possible implementation :D of eval it could be the same function (and the closure would actually be implemented as a hash table or something like that). And eval is actually what lisp is doing all the time, so the only thing that changes here is the scope (=reference to a hash table) That's how, I believe, it could be implemented. (but I've never tried to do that nor read it in the code, so I'm just being a smart ass) > (define (make-bank sum) > (let ((attributes (make-hash-table))) > (define dispatcher > (lambda (which . rest) > (apply (hashq-ref attributes which) rest))) > (hashq-set! attributes 'sum (lambda () > sum)) > (hashq-set! attributes 'add (lambda (n) > (set! sum (+ n sum)))) > dispatcher)) > > (define bank (make-bank 0)) > (bank 'add 2) > (bank 'sum) > => 2 > > > And by using some macros, you can make the syntax look > much prettier. To me it already looks very pretty (and works just as efficiently as my imagination of local-eval operation :>). This might be just what I've been looking for. Thanks a lot. >> Well, I've read some documentation of GOOPS and then >> I took a glimpse at its source. It has at least a few >> disadvantages, for it is an object system implemented in >> scheme -- it is therefore hard to access its objects from C >> (while closures are easily accessible through >> scm_local_eval) and it probably won't run as fast as >> local-eval, at least conceptually. >> > > local-eval is forced to interpret its argument, and is therefore, at least > conceptually, very slow. I very much doubt GOOPS is that slow, > but I don't know how GOOPS is implemented though. :-) Neither do I (I just saw a lot of code, many many layers of code so I've concluded that it is a complex multi-layer system I don't want to get into). I never realized that eval causes such terrible overheads ((procedure-source eval) doesn't show any of the mysteries of the universe :P)