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: Reader syntax for accessing arrays Date: Mon, 09 Jan 2012 16:39:41 +0100 Message-ID: <87hb04996q.fsf@pobox.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1326123603 30386 80.91.229.12 (9 Jan 2012 15:40:03 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 9 Jan 2012 15:40:03 +0000 (UTC) Cc: guile-user@gnu.org To: Panicz Maciej Godek Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Jan 09 16:39:58 2012 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RkHKI-0007pm-30 for guile-user@m.gmane.org; Mon, 09 Jan 2012 16:39:58 +0100 Original-Received: from localhost ([::1]:47195 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RkHKH-0006kG-JJ for guile-user@m.gmane.org; Mon, 09 Jan 2012 10:39:57 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:53240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RkHKA-0006jx-Fo for guile-user@gnu.org; Mon, 09 Jan 2012 10:39:54 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RkHK6-0006DY-7k for guile-user@gnu.org; Mon, 09 Jan 2012 10:39:50 -0500 Original-Received: from a-pb-sasl-sd.pobox.com ([74.115.168.62]:45007 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RkHK5-0006DU-SE for guile-user@gnu.org; Mon, 09 Jan 2012 10:39:46 -0500 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTP id 501538707; Mon, 9 Jan 2012 10:39:45 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=6pGmWAVEQuo0yQcnkVkDBc90gSU=; b=r0bB7N 1Mg+LGgerCSxCtwCK1EAaFZc4bqRl4IyYF9dnjKkzeEwEUsQIraKMBkuYmSZcpXd HOHvmadFR94R8a1/4Rd/mK4BCDJvi65zmqUvcR5QSDg1E6e26lTaJCXPOMmuFWSw l2wwk2KZmut/3HptyREAai4s5UbR92GlZ/ChU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=lcoefjiNuozHH4BkQAkRfQBo8A9Qdiwi 4zIPCddGRX6ouM72OgH9Ar+IIoqBtMf3wQZE/C5FX8/khNtcM5C3YUM+aHC7AhkE PlW6hRMpUsWCotBQFpAUXmu789HrionhSX+YzW+EoU36gf+ndAhO1Un/fOf/aJpa WOdrFd44VEM= Original-Received: from a-pb-sasl-sd.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTP id 49A278706; Mon, 9 Jan 2012 10:39:45 -0500 (EST) Original-Received: from badger (unknown [90.164.198.39]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTPSA id A192F8704; Mon, 9 Jan 2012 10:39:44 -0500 (EST) In-Reply-To: (Panicz Maciej Godek's message of "Tue, 23 Aug 2011 01:17:38 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) X-Pobox-Relay-ID: 27839920-3AD8-11E1-A889-65B1DE995924-02397024!a-pb-sasl-sd.pobox.com X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-Received-From: 74.115.168.62 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:9100 Archived-At: On Tue 23 Aug 2011 01:17, Panicz Maciej Godek writes: > (array-set! a (* (array-ref a i j) 2) i j)) > seems to be unnecessarily prolix, for in C, language designed > specifically to access arrays, > the same operation could be written as > a[i][j] *= 2; With the appropriate macrology, it could look different: (with-array-cells ((x (array-ref a i j))) (set! x (* x 2))) Seems OK to me. There are other possibilities. The macro: (define-syntax with-array-cells (syntax-rules (array-ref) ((_ ((sym (array-ref a idx ...)) ...) body body* ...) (let-syntax ((sym (identifier-syntax (var (array-ref a idx ...)) ((set! var val) (array-set! a val idx ...)))) ...) body body* ...)))) Regards, Andy -- http://wingolog.org/