swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Error Message


From: Barry McMullin
Subject: Re: Error Message
Date: Thu, 07 May 1998 12:02:21 +0100

Rob Kewley wrote:
> The error message is just a warning, and on any system I have used so
> far, it has no effect on execution.  If you want to get rid of the
> annoying message, simply put another layer of parenthesis in your code
> as follows:
> 
> while ((aAgent = [index next])) {

The purists/pedants (choose your own noun) among us would probably
prefer:

  while((aAgent = [index next]) != nil) {

The point is not completely trivial. The compiler is complaining
because it "looks like" you might be using an assignment operator
(=) where you meant to be using a test for equality (==).  This is
a very common novice error, though it so happens that it is not the
case here.  But the solution is not to simply throw in redundant
parentheses to artificially suppress the warning, but rather to rewrite 
the expression, as indicated above, so that it really says
what you meant.

More generally, the expression controlling a while ought to be 
boolean valued; so its reasonable (both for the compiler and any 
human trying to make sense of it) to expect the expression to (
ultimately) rely on some operator that produces a boolean value - 
such as == , but not = . My version of the expression above makes 
explicit (both for the compiler and human readers) that the intention 
is to continue the loop as long as the pointer value is non nil, and 
does not rely on the historical quirk that C-like languages are willing 
to automatically convert pointers to ints, and also to treat ints as 
boolean, and thus treat nil as the same as FALSE.

- Barry-the-pedant...

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.
                  ==================================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]