Newsgroups: comp.lang.python,comp.lang.tcl,comp.lang.scheme,comp.lang.misc,comp.lang.perl
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!news.alpha.net!uwm.edu!news.moneng.mei.com!howland.reston.ans.net!pipex!uunet!fonorola!achilles!news.sandelman.ocunix.on.ca!ecicrl!clewis
From: clewis@ferret.ocunix.on.ca (Chris Lewis)
Subject: Re: Comparing syntaxes  (Re: What language would you use?)
Message-ID: <CyxpI4.78E@ferret.ocunix.on.ca>
Date: Tue, 8 Nov 1994 05:49:16 GMT
References: <39b7ha$j9v@zeno.nscf.org> <39iol8$2rq@csnews.cs.Colorado.EDU> <39iroi$dui@brachio.zrz.tu-berlin.de> <39j22g$655@csnews.cs.colorado.edu>
Organization: eh?
Lines: 49
Xref: glinda.oz.cs.cmu.edu comp.lang.python:2472 comp.lang.tcl:21506 comp.lang.scheme:11046 comp.lang.misc:18888 comp.lang.perl:38273

In article <39j22g$655@csnews.cs.colorado.edu>,
Tom Christiansen  <tchrist@mox.perl.com> wrote:
>An optmizing compiler still has to call k() twice here:

>    x[i][j][k()] = x[i][j][k()] - 7;

>and not here:

>    x[i][j][k()] -= 7;

Actually, no.  Not in C.  C doesn't have enough semantic expressiveness
to allow the C compiler to check for side-effects, and many C compilers
simply assume that there aren't going to be undesirable side-effects,
and optimize it to only one invocation anyways, or optimize it to
evaluate the two k()s in a different order.

As I found out when I did this many years back:

	a = (getchar() - '0') * 10 + (getchar() - '0')

With the optimizer on, my compiler gave me the digits backwards ;-)


>    x[i][j][k()] = x[i][i][k()] - 7;

>I came to loathe Pascal for this once I was used to C and realized 
>how much cleaner assignment operators make your code.

Indeed.  Imagine our amusement when we saw one of the ADA design documents
that was claiming that the increment/decrement (and assignment operators)
should be banned because you might overflow the variable... ;-)

>:to solve the
>:majority of these problems instead of introducing a host of new
>:operators with new problems (I have seen a[i] = i++ too often).

>So?  What's the tremendous problem with this:
>
>    while (i < 100) {
>	a[i] = i++;
>    }

Because you can't guarantee order of evaluation - the subscript may
be incremented before being used...
-- 
Chris Lewis: _Una confibula non sat est_
Phone: Canada 613 832-0541  Ferret list: ferret-request@ferret.ocunix.on.ca
Latest psroff: FTP://ftp.uunet.ca/distrib/chris_lewis/psroff3.0pl17/*
Latest hp2pbm: FTP://ftp.uunet.ca/distrib/chris_lewis/hp2pbm/*
