[R] simple if...else causes syntax error
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Mon Mar 7 18:42:52 CET 2005
Gabor Grothendieck <ggrothendieck at myway.com> writes:
> Jan T. Kim <jtk <at> cmp.uea.ac.uk> writes:
> : Out of personal interest: Does anyone here know why the R parser was
> : designed this way? Personally, I have been coding in R for years in the
> : belief that newline is whitespace, and never even noticed any problems
> : because all my ifs with elses were within functions and thus enclosed
> : in curly braces.
> :
>
> If it did not work that way it would require console lookahead. That is
> it would not know that the if statement was finished and would have
> to wait for the following statement to be completely typed in before
> it could process the if. The way it works now the if statement can
> be processed immediately.
Or put differently, the language designers were not quite aware of the
reason that other command-line languages tend to use explicit
construct terminators like "endif" or "fi".... (I think that is almost
a quote from one of the prominent language experts inside R core, but
I can't pinpoint the details.)
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list