Hi all, Common Lisp has a very useful idiom of SETF that can set values to arbitrary places. For example, one can set (1 2)-th item of an array A as:
(SETF (AREF A 1 2) 20.0d0) Scheme preferred way is to use `*-set!` procedures. However, sometimes it is inconvenient. For example, if I want to swap two elements in the array/vector, I would like to use `swap`: (define-syntax swap (syntax-rules () ((swap ?place1 ?place2 ?tmp) (begin (set! ?tmp ?place1) (set! ?place1 ?place2) (set! ?place2 ?place1))))) But it will only work for vectors if `set!` can act as CL's SETF on generalised places, such as (swap (vector-ref v 5) (vector-ref v 3) tmp) SRFI-17 contains the definition of such a `set!` and I can use it from there (AFAIR Racket supports it). I was wondering if there is more Racket-way of doing this? And is there maybe a reason why `set!` wasn't given the same power as SETF? 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`). Regards, Alexey -- 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.