From cubranic at stat.ubc.ca  Tue Aug 24 16:42:11 2010
From: cubranic at stat.ubc.ca (Davor Cubranic)
Date: Tue, 24 Aug 2010 07:42:11 -0700
Subject: [Rd] small syntax suggestion
In-Reply-To: <4C72D9AC.1080906@sciviews.org>
References: <AANLkTimvja3=JJ-Y8yS=8K+m8ePP7XrCUTEvzg=L9bjn@mail.gmail.com>
	<04831FEE-4137-484E-8942-427085663D2F@stat.ubc.ca>
	<4C72D9AC.1080906@sciviews.org>
Message-ID: <201008240742.12069.cubranic@stat.ubc.ca>

On August 23, 2010 01:27:24 pm Philippe Grosjean wrote:
> They have to write such a code like this:
> 
> if (x < -3) do_something
> 
> That way, there is no ambiguity. Don't you think it's important to
> write clear code, including by using spaces where it makes it easier
> to read,... and less ambiguous, as you just realize?

I fully agree, and I'm sure nobody here would dispute your advice. But 
we all sometimes make typos, and the point here is that the grammar's 
ambiguity makes for hard-to-find bugs.

So, if I may focus us back on the OP's suggestion: "that R simply warn 
about an ambiguity" in 'if' statement's comparison involving '<-[0-9]'. 
It doesn't seem like an unreasonable suggestion. For comparison, GCC 
will do the same thing with C code when the '-Wparentheses' switch if 
assignment is used in a context where a truth value is expected. (E.g., 
'if (x = 3)'.)

It's been a very long time since I looked at Yacc and Lex source, but it 
looks like function 'xxif' in gram.y is the earliest place where we have 
a whole IF statement. AFAICT, this is evaluated in 'do_if' function of 
eval.c. There, the condition is evaluated via 'asLogicalNoNA'. Could 
'do_if' instead use a function similar to 'asLogicalNoNA' but which 
issues a warning if the condition is an assignment?

Davor



[Rd] small syntax suggestion
Davor Cubranic