[Rd] Bug with ..0

2010-05-30 Thread Gabor Grothendieck
This function call returns 3 but should return 32.  ..0 has no special
significance in R as far I know yet it seems to be acting as if it
were ..1 .  Comments?

> ff <- function(..0, ...) ..0
> ff(32, 3)
[1] 3

> R.version.string
[1] "R version 2.11.0 Patched (2010-04-26 r51822)"
> win.version()
[1] "Windows Vista (build 6002) Service Pack 2"

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Bug with ..0

2010-05-30 Thread Duncan Murdoch

On 30/05/2010 3:13 PM, Gabor Grothendieck wrote:

This function call returns 3 but should return 32.  ..0 has no special
significance in R as far I know yet it seems to be acting as if it
were ..1 .  Comments?
  


Actually, ..0 is a reserved symbol.  (This is just barely documented in 
the R Language Defn, with more detail in R Internals.)  It stands for 
the "zeroth element of ..."  That definition makes no sense (indexing of 
... starts at 1), so we should probably generate an error when you use 
it, and perhaps when you try to redefine it by using it as an argument.  
But this is really a case of you doing something you shouldn't, and the 
error handling not slapping you on the wrist.


Duncan Murdoch
  

ff <- function(..0, ...) ..0
ff(32, 3)


[1] 3

  

R.version.string


[1] "R version 2.11.0 Patched (2010-04-26 r51822)"
  

win.version()


[1] "Windows Vista (build 6002) Service Pack 2"

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel



__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Bug with ..0

2010-05-30 Thread Gabor Grothendieck
Note that ?Reserved lists ..1, ..2, to ..9 but does not list ..0.

Also, why is it reserved?  What is the future intended use?

On Sun, May 30, 2010 at 3:40 PM, Duncan Murdoch
 wrote:
> On 30/05/2010 3:13 PM, Gabor Grothendieck wrote:
>>
>> This function call returns 3 but should return 32.  ..0 has no special
>> significance in R as far I know yet it seems to be acting as if it
>> were ..1 .  Comments?
>>
>
> Actually, ..0 is a reserved symbol.  (This is just barely documented in the
> R Language Defn, with more detail in R Internals.)  It stands for the
> "zeroth element of ..."  That definition makes no sense (indexing of ...
> starts at 1), so we should probably generate an error when you use it, and
> perhaps when you try to redefine it by using it as an argument.  But this is
> really a case of you doing something you shouldn't, and the error handling
> not slapping you on the wrist.
>
> Duncan Murdoch
>>
>>
>>>
>>> ff <- function(..0, ...) ..0
>>> ff(32, 3)
>>>
>>
>> [1] 3
>>
>>
>>>
>>> R.version.string
>>>
>>
>> [1] "R version 2.11.0 Patched (2010-04-26 r51822)"
>>
>>>
>>> win.version()
>>>
>>
>> [1] "Windows Vista (build 6002) Service Pack 2"
>>
>> __
>> R-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
>

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Bug with ..0

2010-05-30 Thread Duncan Murdoch

On 30/05/2010 3:44 PM, Gabor Grothendieck wrote:

Note that ?Reserved lists ..1, ..2, to ..9 but does not list ..0.
  


Which version are you looking at? Mine says "‘..1’, ‘..2’ etc," In fact, 
the code just looks for the pattern of two dots followed by something 
that can be converted to a long; see isDDName in src/main/dstruct.c.

Also, why is it reserved?  What is the future intended use?
  


As far as I know, there is none. It is reserved simply because it 
follows the pattern of "..n". It would not be hard to make ..0 specially 
unreserved, but what would be the point?


Duncan Murdoch

On Sun, May 30, 2010 at 3:40 PM, Duncan Murdoch
 wrote:
  

On 30/05/2010 3:13 PM, Gabor Grothendieck wrote:


This function call returns 3 but should return 32.  ..0 has no special
significance in R as far I know yet it seems to be acting as if it
were ..1 .  Comments?

  

Actually, ..0 is a reserved symbol.  (This is just barely documented in the
R Language Defn, with more detail in R Internals.)  It stands for the
"zeroth element of ..."  That definition makes no sense (indexing of ...
starts at 1), so we should probably generate an error when you use it, and
perhaps when you try to redefine it by using it as an argument.  But this is
really a case of you doing something you shouldn't, and the error handling
not slapping you on the wrist.

Duncan Murdoch

  

ff <- function(..0, ...) ..0
ff(32, 3)



[1] 3


  

R.version.string



[1] "R version 2.11.0 Patched (2010-04-26 r51822)"

  

win.version()



[1] "Windows Vista (build 6002) Service Pack 2"

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

  




__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Bug with ..0

2010-05-30 Thread Gabor Grothendieck
On Sun, May 30, 2010 at 4:31 PM, Duncan Murdoch
 wrote:
> As far as I know, there is none. It is reserved simply because it follows
> the pattern of "..n". It would not be hard to make ..0 specially unreserved,
> but what would be the point?

Here is the case I had in mind.

The gsubfn function in the gsubfn package is like gsub except the
replacement string can be a replacement function such that it passes
the back references in the pattern as successive args to the function.
Here it would pass two args to the function represented by (.) and (.)
in the regular expression and then replace the match with the output
of the function which in this case is the sum of the digits surrounded
with angle brackets:

> gsubfn("(.)#(.)", function(...) paste0("<", as.numeric(..1) + 
> as.numeric(..2), ">"), "1#2 3#4")
[1] "<3> <7>"

There is also an option to pass the entire match followed by the back
references to the user function.  In that case it would be nice for
the user to be able to write the user function as follows where ..0
means the entire match.  Here we replace the match with an angle
bracket, the entire match, an equal sign, the sum and an end angle
bracket:

> gsubfn("(.)#(.)", function(..0, ...) paste0("<", ..0, "=", as.numeric(..1) + 
> as.numeric(..2), ">"), "1#2 3#4")
[1] "<1#2=3> <3#4=7>"

Note the use of ..0 to mean the entire match is in this context and
how natural it is.

To do the above the best would be if we could just use ..0 as an
ordinary variable.  Barring that we could replace all occurrences of
..0 with X..0, say, so that:

   function(..0, ...) list(..0, ..1)

would be transformed to the function

   function(X..0, ...) list(X..0, ..1)

and that could work now but that would depend on R not being changed
in the future to issue an error when a function such as f above that
uses ..0 is created.

(Although not illustrated here there is also a formula notation which
allows one to specify the function as a formula whose body is taken to
be the formula's RHS and the args are reconstructed from the RHS free
variables.   In that case the ..0 notation becomes even more useful.)

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel