Hi Alexander,

Thanks for your reply: I had something similar in mind (maybe I should
check out math/array). I was just wondering if there was something more
Racket-like (it still feels that SRFI is somewhat 'foreign' hack). And my
last question remains: wouldn't it be beneficial to have such a generalised
'set!' system-wide? I understand that Racket focusses more on immutable
structures, but there are still vectors and hash-tables which are
inherently mutable and still have their niche.

Best regards,
Alexey

On 29 June 2015 at 18:36, Alexander D. Knauth <alexan...@knauth.org> wrote:

>
> 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