[Rd] The parsing of '{' and a function that equal to '{'

Simon Urbanek simon.urbanek at r-project.org
Fri May 14 22:42:29 CEST 2010


On May 14, 2010, at 3:38 PM, thmsfuller066 at gmail.com wrote:

> Hello All,
> 
> I tried the sample code from the help. Although '{' is assigned to
> 'do', the call syntaxes for 'do' and '{' are not the same ('do' has
> ','s, but '{' has line breaks). I guess there is a difference in
> parsing the code block of 'do' and the code block of '{'. Could you
> please let me know some internal details so that I can understand the
> differences?
> 

{ foo; bar } 

gets parsed into

`{`(foo, bar)

as you illustrated below. You can see that in the resulting expression:

> e=parse(text="{foo; bar}")[[1]]
> attributes(e)=NULL ## remove the original sources
> e
{
    foo
    bar
}
> .Internal(inspect(e))
@102182578 06 LANGSXP g0c0 [NAM(2)] 
  @10082c9b8 01 SYMSXP g0c0 [MARK,gp=0x4000] "{"
  @100edfaa0 01 SYMSXP g0c0 [] "foo"
  @100edfc98 01 SYMSXP g0c0 [] "bar"


and in case you are not familiar with the internal representation:

> quote(`{`(foo,bar))
{
    foo
    bar
}
> .Internal(inspect(quote(`{`(foo,bar))))
@100f99868 06 LANGSXP g0c0 [] 
  @10082c9b8 01 SYMSXP g0c0 [MARK,gp=0x4000] "{"
  @100edfaa0 01 SYMSXP g0c0 [] "foo"
  @100edfc98 01 SYMSXP g0c0 [] "bar"

Cheers,
Simon




>> do=get("{")
>> do(x <- 3, y <- 2*x-3, 6-x-y)
> [1] 0
>> {
> +   x <- 3
> +   y <- 2*x-3
> +   6-x-y
> + }
> [1] 0
>> x
> [1] 3
>> y
> [1] 3
>> 
> 
> -- 
> Tom
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
>



More information about the R-devel mailing list