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

Re: perhaps I've missed something ...

>... but I fail to see the appeal of this mechanism. As far as I can 
>tell, a scheme implementation which conforms to this SRFI allows me 
>to write
>(set! (car x) 5)
>rather than
>(set-car! x 5)

It's useful for syntactic (rather than procedural) abstraction.  It
allows you to write macros like this:

  ;; inc! increments whatever is stored in the "location" that 
  ;; is its argument.

  (define-syntax inc!
    (syntax-rules ()
      ((inc! ?loc)
       (set! ?loc (+ ?loc 1)))))

Without SRFI-17, you can at most pass a variable as a location:

  (inc! x)  => (set! x (+ x 1))

but with SRFI-17 you can do better:

  (inc! (car x)) => (set! (car x) (+ (car x) 1))
  (inc! (vector-ref v i)) => (set! (vector-ref v i) (+ (vector-ref v i) 1))