[Rd] small syntax suggestion

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Mon Aug 23 15:15:07 CEST 2010


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



More information about the R-devel mailing list