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



>>>>> "Per" == Per Bothner <per@xxxxxxxxxxx> writes:

Per> The real question is: Does using set! for both variable assignment and
Per> field assignment lead to confusion, programming mistakes,
Per> hard-to-maintain programs, or more difficulty training
Per> programmers?

Definitely.  I just taught this stuff to 250 beginning students last
week, and many had been confused by the obscurity in programming
languages they had learned before.  The prototypical example goes
something like this:

(define x 23)

(define f
  (lambda (x)
    (set! x 42)))

(f x)
x => ?

Alternatively:

(define x (cons 23 #f))

(define f
  (lambda (x)
    (set-car! x 42)))

(f x)
(car x) => ?

Again, SET! has interactions with the meta-level (lexical scoping,
modifies meta-level entities) that data structure mutators don't have.

Students who don't understand the subtleties tend to either avoid
using the associated features altogether, or reason about program
behavior by running the program and looking, rather than understanding
the underlying semantics.

What I fail to see is a good reason *not* to rename the new
construct.  Even Common Lisp has both SETQ and SETF.

-- 
Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla