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

Re: perhaps I've missed something ...

This page is part of the web mail archives of SRFI 17 from before July 7th, 2015. The new archives for SRFI 17 contain all messages, not just those from before July 7th, 2015.

At 5:37 PM -0500 1/20/00, Lars Thomas Hansen wrote:
 >... 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))

Let me clarify. I have nothing against syntactic abstraction. My concern is primarily with the unnecessary overloading of the set! primitive. Replace set! with set-location! (or set-l! if you prefer) and you have a language extension which
a) I would not personally use, but
b) I would not object to (much).

john clements