Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!newsserver.jvnc.net!nntpserver.pppl.gov!princeton!news.princeton.edu!blume
From: blume@atomic.cs.princeton.edu (Matthias Blume)
Subject: Re: why is set! not called set ?
In-Reply-To: "Kevin B. Thompson"'s message of 30 Mar 1995 19:45:40 GMT
Message-ID: <BLUME.95Mar30171825@atomic.cs.princeton.edu>
Originator: news@hedgehog.Princeton.EDU
Sender: news@Princeton.EDU (USENET News System)
Nntp-Posting-Host: atomic.cs.princeton.edu
Organization: Princeton University
References: <3lf1p4$6rs@apollo.jcpenney.com>
Date: Thu, 30 Mar 1995 22:18:25 GMT
Lines: 43

In article <3lf1p4$6rs@apollo.jcpenney.com> "Kevin B. Thompson" <kbt2@jcpenney.com> writes:

   Why does set! have an exclamation point on the end of it
   even though it doesn't perform a mutation? 

The problem is that you have misunderstood what DEFINE and SET! do.

   Example:

   > (define x 0)
   > (define y x) ;; x and y now refer to the same object

The comment is false.  X and Y now refer to distinct locations, both
of which currently contain the same object.

   > x
   0
   > y
   0
   > (set! x 1) ;; i expect this to mutate the object x refers to
   > x
   1

Your expectation is wrong.  SET! mutates the *location* X is bound to.

   > y ;; i expect this to be 1
   0

No, the location Y is bound to (which is not the same location X is
bound to) has not been mutated.

   ..but it's not! set! is not mutating, but simply binding
   the symbol to a fresh location holding the new value.

No, SET! is not binding X to a new location.  It is modifying the
location X is bound to.

   why is set! not called set ?

Because it has a side effect (it mutates a location).

--
-Matthias
