From pinard at iro.umontreal.ca  Wed Jul 19 16:29:47 2006
From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard)
Date: Wed, 19 Jul 2006 10:29:47 -0400
Subject: [Rd] Patch to allow negative argument in head() and tail()
In-Reply-To: <17597.57223.151500.824538@stat.math.ethz.ch>
References: <200607171503.34713.vincent.goulet@act.ulaval.ca>
	<17596.40686.710925.321109@stat.math.ethz.ch>
	<200607181356.06360.vincent.goulet@act.ulaval.ca>
	<20060718214153.GA5151@alcyon.progiciels-bpi.ca>
	<17597.57223.151500.824538@stat.math.ethz.ch>
Message-ID: <20060719142947.GA6942@phenix.progiciels-bpi.ca>

[Martin Maechler]

>  Regarding unix command line compatibility:
>  Note that there, 'tail'  is *really* not what we want to imitate:

>  "3" is the same as "-3" but different from "+3" :

>I know that there is some "good" reason for the behavior of
>'tail' in "Unix" 
>  { tail -3 === tail -n  3   and
>    tail -3 === tail -n -3      }                            ***

>but of course, we can't be compatible here, because in S
>(and most reasonable languages :-) 
>"3 == +3"  and  "3 != -3" !

I'm not sure I understand you fully, or maybe there is a typo on the 
starred line above.  When I speak about GNU "head" and "tail" behaviour,
I'm really meaning the internal behaviour once option values have been 
decoded, but certainly not option representation themselves.

The strange spirit of Unix designers show, where while `-' is only meant 
as an option introducer, by a kind of typographical pun, it is 
temporarily seen a negative sign when the time comes to negate a value, 
and this is the reason `+' was sometimes used, that is, as a humorous 
way to mean a minus sign in option context.  So, `+' really means `-' 
sometimes.  This is a similar kind of humour which later yielded 
a better "more" program to be named "less" :-).

For "head" and "tail", these programs were accepting a number as first 
argument without requiring it to be introduced by the usual `-'.  POSIX 
later came in and got rid of this irregularity.  Moreover, within GNU, 
`+' option introducer was once reserved for so called "long options" and 
consequently unavailable for the above pun, but later freed again when 
the `--' convention was adopted instead of `+' for long options.  Many 
implementations attempted to be compatible to both POSIX and pre-POSIX 
specifications.  GNU implementation also had to cope with their own 
varying option standards, as well as a lot of contradictory pressure 
from users and within.  Even nowadays, as a futile attempt to reconcile 
some incompatible trends that cannot be dismissed, a few environment 
variables can be set to alter how these tools interpret and decode the 
value of the dreaded option.  As you may guess, confusion resulted, and 
those of us who followed it all never fully recovered from all the brain 
damage :-).  [Another tiny corner of Unix where sign confusion blatantly 
existed was "nice", this tool meant to alter process priority.]

*Once* the real value has been decoded out of the option, the current 
convention is as follow, given that N is a positive number:

  Value  "head" tool                    "tail" tool

  N      Show N initial lines           Show N last lines
  -N     Show all but N last lines      Show all but N first lines

Hoping that this clarification may be helpful in the whole thinking! :-)

-- 
Fran?ois Pinard   http://pinard.progiciels-bpi.ca



[Rd] Patch to allow negative argument in head() and tail()
=?iso-8859-1?Q?Fran=E7ois?= Pinard