unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: Panicz Maciej Godek <godek.maciek@gmail.com>
Cc: guile-user@gnu.org
Subject: Re: Reader syntax for accessing arrays
Date: Mon, 09 Jan 2012 16:39:41 +0100	[thread overview]
Message-ID: <87hb04996q.fsf@pobox.com> (raw)
In-Reply-To: <CAMFYt2ZqK7ax7uU3os0c+Oe_gGFY0aiPsHoVdCc_Zu2Xe41GeQ@mail.gmail.com> (Panicz Maciej Godek's message of "Tue, 23 Aug 2011 01:17:38 +0200")

On Tue 23 Aug 2011 01:17, Panicz Maciej Godek <godek.maciek@gmail.com> 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/



      parent reply	other threads:[~2012-01-09 15:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-22 23:17 Reader syntax for accessing arrays Panicz Maciej Godek
2011-08-23  8:10 ` Johan Hidding
2011-08-23 18:03   ` Panicz Maciej Godek
2011-08-24 10:51     ` Ludovic Courtès
2011-08-24 18:45       ` Panicz Maciej Godek
2011-08-24 19:52         ` Johan Hidding
2011-08-26 21:02           ` Panicz Maciej Godek
2012-01-09 15:39 ` Andy Wingo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87hb04996q.fsf@pobox.com \
    --to=wingo@pobox.com \
    --cc=godek.maciek@gmail.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).