On Jun 29, 2015, at 5:56 AM, Alexey Cherkaev <alexey.cherk...@gmail.com> wrote:

> For example, I was thinking of defining syntax to access my implementation of 
> multidimensional arrays
> as
> 
> (define-syntax aref
>  (syntax-rules (set!)
>    [(set! (aref ?a ?i ...) ?v) (array-set! ?a ?i ... ?v)]
>    [(aref ?a ?i ...) (array-ref ?a ?i ...)]))
> 
> but obviously it won't work now as `set!` expects the `id` not an expression 
> (`syntax-id-rules` won't work either as `aref` is not an `id`).


#lang racket
(require srfi/17 math/array)
(define (aref a . is)
  (array-ref a (list->vector is)))
(set! (setter aref)
      (λ (a . is+v)
        (match-define (list is ... v) is+v)
        (array-set! a (list->vector is) v)))
(define a (mutable-array #[#[1 2] #[3 4]]))
(aref a 0 1)
(set! (aref a 0 1) 20)
(aref a 0 1)

If you wanted, you could also define your own version of set! that does what 
you want, which (I think) you would need to do if you needed aref to be a macro.


-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to