[ESS] = and test suites (was: Re: indentation when using = rather than <-)

Martin Maechler maechler at stat.math.ethz.ch
Sat Feb 4 12:43:37 CET 2006

>>>>> "tony" == A J Rossini <blindglobe at gmail.com>
>>>>>     on Sat, 4 Feb 2006 11:10:56 +0100 writes:

    tony> Tim - That's a hard one.  Despite the fact that I
    tony> think that the use of "=" (or "_") for assignment is a
    tony> cardinal sin,

   You just throw away part of the expressiveness of the S
   In S, we have assignment     by "<-"
   and function argument naming by  "="  {both in function calls
   and function definitions for the default values}.

   And it's very useful to differentiate the two, and it does make
   sense to fontify the assignment operator, but it's much less
   sensical to fontify all "=" !

   In the languages that use "=" assignment, 
   there is no other use of "=" and hence no language ambiguity in 
   things like
	  plot(x = y)

    tony> I am not sure that the ESS code is 
    tony> factored well to allow for simple replacement /
    tony> additions of "=" as assignment, and it should be.

Indeed.  I must admit to have been startled by Tim's example
leading to bad indentations;
Of course I never misuse the "=" operator (*), and so don't see
examples, but still;  why is our indentation not guided by the
 "(...)" parentheses matching?

(*):  Recent version of ESS for a good reason have the function
      M-x ess-fix-EQ-assign   
      which tries to guess at least some of the misuses of "="
      and replace them by " <- "
      ess-fix-EQ-assign is part of the   M-x ess-MM-fix-src
      function which I use every time I get S source files from
      other people.

    tony> What I'd think about is looking for uses of "_" for
    tony> assignment in the lisp code for S/S-PLUS, and when
    tony> appropriate, replaceing them with "=".

(or just run under R where "_" will give syntax errors in most cases)

Also, ESS has  M-x ess-fix-miscellaneous
which replaces quite a few of the "_" uses by " <- "

    tony> On a side note, we really ought to have a test suite
    tony> for font-locking.  

and for indentation, and ...  good idea, but how
can one do automated testing {via 'make' i.e. scripts !} of such
emacs / ESS features?

    tony> I know we have (had?) some for SAS,
    tony> but it would be good to have some for the various
    tony> "allowable" (heinous) approaches for coding that
    tony> S-PLUS and R allow, to make sure we get indentation
    tony> right for unbelievers.

    tony> On 3 Feb 2006 14:27:37 -0800, Tim Hesterberg
    tony> <timh at insightful.com> wrote:
    >> I'm trying to move away from using _ for assignment, but
    >> rather than <- I want to use = (for a number of reasons,
    >> the biggest of which is that <- is a barrier to new users
    >> adopting the S language).
    >> Unfortunately, ESS does not treat <- and = the same for
    >> indentation (example below).
    >> How would I get ESS to treat "=" the same as "<-" for
    >> purposes of indentation?
    >> I tried adding "=" to the ess-S-assign-ops variable, but
    >> that didn't seem to affect indentation.  There is a
    >> comment in the definition of the variable suggesting the
    >> omission of "=" is intentional, so I'm wondering about
    >> possible negative ramifications of modifying the ESS code
    >> to make indentation work as I like.
    >> --------------------------------------------------
    >> Example:
    >> If I create the following functions with no initial
    >> blanks, then run ess-indent-exp from the beginning of
    >> each function, I get the following; I'd like indenting
    >> the second version to be similar to indenting the first.

>>     f <- function(x) {
>> 	a
>> 	if(b) {
>> 	    c <- foo1(x = 2, y = 3, foo2(z = mean(x)),
>> 		      a, b = 5)
>> 	    for(i in 1:n)
>> 		d[i] <- foo3(z, foo4(a = 3,
>> 				     b =
>> 				     5, c, foo5(d)))
>> 	}
>>     }
>>     f = function(x) {
>> 	a
>> 	if(b){
>> 	    c = foo1(x = 2, y = 3, foo2(z = mean(x)),
>> 	    a, b = 5)
>> 	    for(i in 1:n)
>> 		d[i] = foo3(z, foo4(a = 3,
>> 		 b =
>> 		 5, c, foo5(d)))
>> 	}
>>     }

More information about the ESS-help mailing list