[comp.lang.scheme] Using the return value of set! et al

pk@cs.tut.fi (Kellom{ki Pertti) (04/02/91)

>>>>> On 26 Mar 91 15:59:05 GMT, quale@saavik.cs.wisc.edu (Douglas E. Quale) said:
> Re: using values returned by set! et al mentioned in a previous post
> I've never seen any Scheme code that depended on the value returned by set!,
> but it would be easy to make this mistake.  Some Schemes return something
> like #[undefined value] for these cases.  Although not defining the return
> values of these functions can enable a compiler to generate faster code, I
> think it would be better to define return values for them.  The return values
> wouldn't be used very frequently and often the compiler can see this and
> generate the same code as if the return value were undefined.

I have lately seen a lot of Scheme code that depends on the reutrn
value of set!, vector-set! etc. I'm currently teaching a course in
data structures and algorithms, and as a class project the students
are writing a program to simulate a mouse in a maze. The first
assignment was to write a data sructure modeling the maze, and a lot
of the students are writing code like

(define (make-maze ...)
  (let ((vec (make-vector ...)))
     (vector-set! vec [whatever initialization is needed])))

The interpreter they are using returns vec as the return value of
vector-set!, so the students happily use the return value. I have seen
a lot of code like this, and I don't think you can entirely blame the
students for it. They are new to the language, and they already have
enough to think about. If multiple values become part of the standard,
I would very much like to see set! etc. return zero values, because
that would eliminate most of the problem from the teacher's point of
view. 
--
Pertti Kellom\"aki (TeX format)  #       These opinions are mine, 
  Tampere Univ. of TeXnology     #              ALL MINE !
      Software Systems Lab       #  (but go ahead and use them, if you like)

mob@media-lab.MEDIA.MIT.EDU (Mario O. Bourgoin) (04/03/91)

I feel lost in reading these debates on whether SET! and its avatars
should return a useful value and whether people should use it.
There's a game of terseness in computer programming where people work
very hard to say something with the smallest number of statements that
the language allows.  Like most, I play this game and justify it,
rightly or wrongly, in the name of efficiency.  But there's another,
more valuable game to play: that of making programs readable and
understandable by others.  While the two games aren't always at odds,
I think that the latter game should win out over the former when
there's a conflict.

--Mario

P.S. I say that the game of terseness is usually justified on ground
of efficiency, but I've lately come to suspect that most compilers
either aren't able to make use of the extra information given to them
when such things as the return value of a set is used, or that they
are able to figure it out for themselves already.  Is this true?
Furthermore, I think that that kind of information is not necessarily
what the compiler would need to best optimize the code because it can
at best lead to local changes, not global re-writes.  Can someone
confirm this?