From simon.urbanek at r-project.org  Fri May 14 22:42:29 2010
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Fri, 14 May 2010 16:42:29 -0400
Subject: [Rd] The parsing of '{' and a function that equal to '{'
In-Reply-To: <AANLkTil-jwpC1dCv3L5gYVfJFXehSokXyRyxbZLs5RfX@mail.gmail.com>
References: <AANLkTil-jwpC1dCv3L5gYVfJFXehSokXyRyxbZLs5RfX@mail.gmail.com>
Message-ID: <ECDC0BBD-4125-411B-881B-5E92FCEA5072@r-project.org>


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
> 
>



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