[plt-scheme] vectors by value

From: Bill Richter (richter at math.northwestern.edu)
Date: Fri Feb 7 21:57:41 EST 2003

John, let me add to Robby's expert analysis:

   If this doesn't help, please check out http://www.htdp.org/ and
   read part vii (changing the state of variables) and viii (changing
   compound values).

You didn't raise a newbie question, because your code won't run in
Advanced Student:

(define mylist '(hi there))
(define (changemylist x)
    (set! x (append x '(this is new)))

Welcome to DrScheme, version 203.
Language: Advanced Student.
set!: expected a defined name after `set!', but found a function argument name

So 38.4 The Meaning of Advanced Scheme of HtDP will not explain your
code.  That's of course a big advantage of Advanced Scheme, the
simplified semantics, which mostly lets you use the substitution rule.

What you need to read is Section 40 (in viii as Robby said), which is
about constructors & mutators.  Advanced Student has a define-struct
mechanism that lets you perform the illegal code above. In particular:

     Mutable Structures

     Mixing set! and Structure Mutators: When a program uses both
     set!-expressions and structure mutators, our evaluation rules
     fail for some cases.  Specifically, they don't explain sharing
     properly. Consider this program fragment:

        (define the-point (make-posn 3 4))

        (define another-point the-point)

          (set! the-point 17)
          (= (posn-x another-point) 3))

     According to our rules, the two definitions refer to the same
     structure. The second one does so by indirection. The
     set!-expression changes what the-point stands for, but it
     shouldn't affect the second definition. In particular, the
     program should produce true. If we were to use our rules in a
     naive manner, we would not be able to validate this point.

Posted on the users mailing list.