From b.rowlingson at lancaster.ac.uk  Mon Aug 23 15:15:07 2010
From: b.rowlingson at lancaster.ac.uk (Barry Rowlingson)
Date: Mon, 23 Aug 2010 14:15:07 +0100
Subject: [Rd] small syntax suggestion
In-Reply-To: <AANLkTimvja3=JJ-Y8yS=8K+m8ePP7XrCUTEvzg=L9bjn@mail.gmail.com>
References: <AANLkTimvja3=JJ-Y8yS=8K+m8ePP7XrCUTEvzg=L9bjn@mail.gmail.com>
Message-ID: <AANLkTinwC0h+oX2QhcskS_9xRuws=X9XQ2RuGnOxVCyG@mail.gmail.com>

On Sun, Aug 22, 2010 at 4:33 PM, ivo welch <ivo.welch at gmail.com> wrote:
> Dear R development Team: ?I really know very little, so you may ignore
> this post. ?I have found that my students often make the mistake of
> mixing up comparisons and assignments with negative numbers:
>
> ?if (x<-3) do_something;
>
> I parenthesize, but every once in a while, I forget and commit this
> mistake, too. ?so, I would suggest that R simply warn about an
> ambiguity. ?that is, it could suggest a space either between the < and
> - , or after the <- .
>
> ?x< -3 ?## means comparison already
> ?x<- 3 ?## means assignment already
> but warn when
> ?x<-3 ?## ambiguity warning instead of assignment
> ?x<-(whatever) ?## ok
>
> just a suggestion...
>

 If you tell your students not to use '<-' for assignment, then they
can't make this mistake, because = for assignment has additional
restrictions on it:

 > x
 [1] 3
 > if(x=3)print("yay")
 Error: unexpected '=' in "if(x="

Anyway, if students didn't make mistakes how will they learn about debugging?

Barry



[Rd] small syntax suggestion
Barry Rowlingson