From: Software Scavenger
Subject: zerop
Date: 
Message-ID: <a6789134.0110231512.7ee91c7a@posting.google.com>
What is the advantage of (zerop x) over (= 0 x)?  I.e. why does zerop
exist?  And if there is some good reason for having such a function,
why is it not named 0= to be in style with 1+ and 1-?

From: Kent M Pitman
Subject: Re: zerop
Date: 
Message-ID: <sfw6695x6q7.fsf@world.std.com>
··········@mailandnews.com (Software Scavenger) writes:

> What is the advantage of (zerop x) over (= 0 x)?  I.e. why does zerop
> exist?  And if there is some good reason for having such a function,
> why is it not named 0= to be in style with 1+ and 1-?

The function and its name are historical and occur in a lot of Lisp texts
going back a long way.  There's little reason to perturb it.

ZEROP is useful because it can be mapped and used as a one-place predicate
in various :test situations.  Ditto with PLUSP and MINUSP which you didn't
ask about.

IMO, 1+ and 1- are not terrific models of naming to be emulated, btw.
(1- x) confuses a lot of people.  My recollection is that we called it
-1+ in Yale Scheme, which I liked better.  It might get us into questions
of whether it was 0= or =0, too.  I personally find it abhorrent to see
(= 0 x); I prefer (= x 0).  I always put the constant term I'm searching 
for second and the term I'm thumbing through first.  The math may be
symmetric, but the conversational English is not; to me "if 0 is x then..."
sounds like you're waiting for 0 to change its value to become like x.
(This is partly because in English, "x is red" can also asymmetrically 
put a predicate in the second position, but not the first.)  Useless
quibbles like this are good reasons to just not muck with a perfectly
serviceable status quo.  

I also think Scheme's name zero? is quite aesthetic, btw, but in CL we
spell "?" as "p" out of tradition, and it might as well be more or
less uniformly done thus.
From: David McClain
Subject: Re: zerop
Date: 
Message-ID: <_9oB7.42$kY5.81574@news.uswest.net>
> of whether it was 0= or =0, too.  I personally find it abhorrent to see
> (= 0 x); I prefer (= x 0).  I always put the constant term I'm searching
> for second and the term I'm thumbing through first.  The math may be
> symmetric, but the conversational English is not; to me "if 0 is x
then..."
> sounds like you're waiting for 0 to change its value to become like x.

This is another learned defensive tactic that arises from writing C code...
It is too easy to write x = 0 when one really meant to write x == 0. So
instead, switching the order to 0 == x makes the first mistake wholly
unacceptable to the compiler and you don't get burned trying to track down
that nasty little bug....

- DM
From: Erik Naggum
Subject: Re: zerop
Date: 
Message-ID: <3212878813839675@naggum.net>
* Kent M Pitman
| I personally find it abhorrent to see (= 0 x); I prefer (= x 0).

  Since I frequently write (<= 0 foo <limit>), and read this as a test
  whether the arguments are increasing non-monotonically, instead of the
  more informal "less than or equal", which works only for two arguments in
  my view, just like (+ a b c) as which I read "sum of" rather than "plus",
  I find it more convenient to start the argument list with the constant.

  Also, in (< 4 x), the symbol < has the visual appeal that the arguments
  should have increasing values from left to right for the expression to be
  true, and likewise for > for decreasing values.  Using infix syntax, I
  would write x > 4, but I would also read it backwards.

///
-- 
  Norway is now run by a priest from the fundamentalist Christian People's
  Party, the fifth largest party representing one eighth of the electorate.
-- 
  The purpose of computing is insight, not numbers.   -- Richard Hamming
From: Thomas F. Burdick
Subject: Re: zerop
Date: 
Message-ID: <xcvsnc92206.fsf@famine.OCF.Berkeley.EDU>
Erik Naggum <····@naggum.net> writes:

> * Kent M Pitman
> | I personally find it abhorrent to see (= 0 x); I prefer (= x 0).
> 
>   Since I frequently write (<= 0 foo <limit>), and read this as a test
>   whether the arguments are increasing non-monotonically, instead of the
>   more informal "less than or equal", which works only for two arguments in
>   my view, just like (+ a b c) as which I read "sum of" rather than "plus",
>   I find it more convenient to start the argument list with the constant.
> 
>   Also, in (< 4 x), the symbol < has the visual appeal that the arguments
>   should have increasing values from left to right for the expression to be
>   true, and likewise for > for decreasing values.  Using infix syntax, I
>   would write x > 4, but I would also read it backwards.

I'm likely to write (= x 0), but I'd probably write

         (if (= 0 (foo x y (baz (car z)
                                (cdr z))))
             ...)

rather than

         (if (= (foo x y (baz (car z)
                              (cdr z)))
                0)
             ...)

which I find significantly less readable

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'