[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reader syntax for accessing arrays

From: Andy Wingo
Subject: Re: Reader syntax for accessing arrays
Date: Mon, 09 Jan 2012 16:39:41 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

On Tue 23 Aug 2011 01:17, Panicz Maciej Godek <address@hidden> 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* ...))))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]