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: Mon, 14 Jul 2008 23:14:59 +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 1216070115 20754 80.91.229.12 (14 Jul 2008 21:15:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 14 Jul 2008 21:15:15 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Jul 14 23:16:03 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 1KIVOs-00019U-Me for guile-user@m.gmane.org; Mon, 14 Jul 2008 23:16:02 +0200 Original-Received: from localhost ([127.0.0.1]:55393 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KIVO0-0000QI-CV for guile-user@m.gmane.org; Mon, 14 Jul 2008 17:15:08 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KIVNw-0000Py-2m for guile-user@gnu.org; Mon, 14 Jul 2008 17:15:04 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KIVNu-0000Pf-OB for guile-user@gnu.org; Mon, 14 Jul 2008 17:15:03 -0400 Original-Received: from [199.232.76.173] (port=35216 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KIVNu-0000Pc-Ge for guile-user@gnu.org; Mon, 14 Jul 2008 17:15:02 -0400 Original-Received: from wf-out-1314.google.com ([209.85.200.175]:42789) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KIVNu-0001AR-OB for guile-user@gnu.org; Mon, 14 Jul 2008 17:15:03 -0400 Original-Received: by wf-out-1314.google.com with SMTP id 28so4432767wfc.24 for ; Mon, 14 Jul 2008 14:15:00 -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:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=r0bDrs9ClMnIdu3CK/DDLCfZx9BVPtSTvpD7I2iGoDk=; b=e92UoQ8XwVLY+layY3UxN7lKsx/DgO6BSut23Q3An86367oRI4+mljKagu2/+nETt+ 1xtO2gwHxNw9Pb5JMBSiEka5Eow0ApA0tiDubXty3gZZaUdaj2IfT+kCFZcw81oQAi2B KUjfdUmfUEcoJs0QmOUWzypCeKhlYbUbIbLkI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=nqiNW9q6JMF7EPIjVg+XVVDiCbB5lmbbXpwJmW3QsKrW5U/0pbCDMQFZfG2mvpmbht Z4icH9nm+N39TI9o2gVqK71Zh0bckdl8yUo0ORpYUk2aNa+eH6079oWu/o7FUxQDqv6o ytevyNHGoJdpB0OetW7lce6k4tvJQnkje4S+Y= Original-Received: by 10.142.52.9 with SMTP id z9mr4365990wfz.70.1216070099674; Mon, 14 Jul 2008 14:14:59 -0700 (PDT) Original-Received: by 10.142.133.13 with HTTP; Mon, 14 Jul 2008 14:14:59 -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:6657 Archived-At: Kjetil S. Matheussen: > I think local-eval is necessary for making > a namespace system of the below type without having to use > codewalking macros to expand the bodies of functions: > > (define-namespace bank) > (def-bank sum 0) > (def-bank (add n) > (set! sum (+ n sum)) ;; Note that it's enough to write "sum". > > (bank.add 50) > bank.sum > => 50 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. > 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? > (def-class > (def-var sum 0) > (def-method (add n) > (set! sum (+ n sum))) > > (define bank (new )) > (-> bank add 50) > (-> bank sum) > => 50 > > There's a bunch of these systems for scheme. > The syntax above is used from > http://snd.cvs.sourceforge.net/snd/cvs-snd/oo.scm?view=log > > Guile's own OO system called GOOPS is also very nice. > GOOPS a quite verbose but very powerful and a lot > more interactive. It's similar to CL's CLOS, which > you should look at if you are not familiar with > already. 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. (It is essential to observe that closures are already like objects and that any additional object systems are doubtfully needed with closures implemented properly -- as long as you can access their scope) Yet still I reserve the right to be wrong as a newbie :)