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: References/locations Date: Mon, 11 Aug 2008 01:00:21 +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 1218409247 11463 80.91.229.12 (10 Aug 2008 23:00:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 10 Aug 2008 23:00:47 +0000 (UTC) Cc: guile-user@gnu.org To: "Kjetil S. Matheussen" Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Aug 11 01:01:38 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 1KSJus-0000Fi-3r for guile-user@m.gmane.org; Mon, 11 Aug 2008 01:01:38 +0200 Original-Received: from localhost ([127.0.0.1]:55321 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KSJtw-0004Nv-7Z for guile-user@m.gmane.org; Sun, 10 Aug 2008 19:00:40 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KSJth-0004Mg-5G for guile-user@gnu.org; Sun, 10 Aug 2008 19:00:25 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KSJtf-0004J1-I4 for guile-user@gnu.org; Sun, 10 Aug 2008 19:00:24 -0400 Original-Received: from [199.232.76.173] (port=48117 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KSJtf-0004Io-Aj for guile-user@gnu.org; Sun, 10 Aug 2008 19:00:23 -0400 Original-Received: from wf-out-1314.google.com ([209.85.200.173]:50104) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KSJte-0003i4-UK for guile-user@gnu.org; Sun, 10 Aug 2008 19:00:23 -0400 Original-Received: by wf-out-1314.google.com with SMTP id 28so1596583wfc.24 for ; Sun, 10 Aug 2008 16:00:21 -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=a3dQNnJ0DtVQuKH6F0opj7kNbIViPDqVmqt4IFEpims=; b=tDUxbWTTcS+ScYTefPHUkAPDfxi2ooGmcU61pBtgyhbCSP5XZTAXAT+ighVpQKbxU8 hyRXxodUlccIXQ9pwlv3oSaJ4T6PYero8fAhqiqU7zCC9feB1KDSku9adiwARaTNBwJW tbNLaKApOZCqoyxbcEz6aWEiOITYJYILeFP5A= 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=pxE5sPzwRSP9GkRc+iYaC152QRFjoQt/M6oWiVwZyaAsonJ9OoPA7ppdYZ3hf3JO+N XCEMhmZyw8QfkI+9/zT1zTzXAc1gBRhxSZfspfnBTs5As3OBGLsBV+eN17BTVhAqg6Sb 9C77wmE5D1ENxFbmh0k8glzks6GT8ihJoQErs= Original-Received: by 10.142.162.5 with SMTP id k5mr1860973wfe.260.1218409221677; Sun, 10 Aug 2008 16:00:21 -0700 (PDT) Original-Received: by 10.142.164.4 with HTTP; Sun, 10 Aug 2008 16:00:21 -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:6737 Archived-At: Kjetil: >> Hi, >> it's me again, asking silly questions. > > Not at all, your questions are very good. :-) That's werid. Every time I write a post I've got the strange feeling that I'm thinking in the way that should be forbidden :) I can give you the background of this idea. I've been trying to implement a vector-based object-oriented system (I'm rather reluctant towards goops). I imagine that it could be used in the following manner (borrowed from C++): (define sphere (class () ;; public slots (x y radius) ;; private slots ((move (dx dy) ;; methods (set! x (+ x dx)) (set! y (+ y dy))) (scale (factor) (set! radius (* radius factor)))))) Obviously, the "class" macro should convert methods to lambdas. For "move" that would be: (lambda(self dx dy) (let((x (vector-loc self (get-hash-table properties 'x))) (y (vector-loc self (get-hash-table properties 'y))) (radius (vector-ref self (get-hash-table properties 'radius)))) (set! x (+ x dx)) (set! y (+ y dy))) Obviously, the hash table reference would have to be evaluated during macro expand to provide the maximum efficiency. (If you have any other solutions to this problem, I'm open to suggestions) >> Besides I think that the names "hash-ref" >> and "vector-ref" are confusing, since they >> don't return references, but values (therefore >> the names like "vector-get" or "hash-get" would >> be more apropreate) >> > > Never thought about that, but it sounds > correct. vector-get and hash-get would > probably be mroe apropreate names. On the other hand the world of scheme seems to have gotten used to such convention. > Well, here's a relatively clean way, I think: > > (define-macro (location name) > (define new-val (gensym)) > `(lambda (,new-val) > (set! ,name ,new-val))) > > (define old-set! set!) > > (define-macro (set! a b) > `(if (procedure? ,a) ;; Needs a better check. > (,a ,b) > (old-set! ,a ,b))) > > > guile> (define x 10) > guile> (define y (location x)) > guile> (set! y 20) > guile> x > 20 > guile> That's amazing! Whenever I think of something (and imagine how difficult would it be to implement), you come up with a solution taking only a few lines of code :) (I only have to think how would it perform in practice) Thanks M.