Re: perhaps I've missed something ...
John Clements 20 Jan 2000 22:57 UTC
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