From pdalgd at gmail.com  Fri Oct 21 20:13:48 2016
From: pdalgd at gmail.com (peter dalgaard)
Date: Fri, 21 Oct 2016 20:13:48 +0200
Subject: [Rd] anonymous function parsing bug?
In-Reply-To: <1ffe617d-5699-95ee-6846-7741ca75e351@gmail.com>
References: <97dcb35c-9173-5fc6-a499-680a4be15a94@gmail.com>
	<CAF8bMcakY4mDNiFqi2Tj8JeuLXQ74utkrC4J4ArWQLx0LX=E8w@mail.gmail.com>
	<1852931e-89bd-3e9f-934c-2a42361ed414@gmail.com>
	<CAF8bMcaxjGukTYgcOEbQc6XfF51q65CwqWYPzkxaymGBKS-1Ng@mail.gmail.com>
	<1ffe617d-5699-95ee-6846-7741ca75e351@gmail.com>
Message-ID: <4B5350C2-2E8B-42E6-8BFD-D52D25ED2D96@gmail.com>


> On 21 Oct 2016, at 19:17 , Wilm Schumacher <wilm.schumacher at gmail.com> wrote:
> 
> Am 21.10.2016 um 18:10 schrieb William Dunlap:
>> Are you saying that
>>    f1 <- function(x) log(x)
>>    f2 <- function(x) { log } (x)
>> should act differently?
> yes. Or more precisely: I would expect that. "Should" implies, that I want to change something. I just want to understand the behavior (or file a bug, if this would have been one).

I think Bill and Luke are failing in trying to make you work out the logic for yourself...

The point is that 
{
  some_computation
}(x)

is an expression that evaluates some_computation and applies it as a function to the argument x (or fails if not a function). 

When you define functions, the body can be a single expression, so

f <- function(a)
{
  some_computation
}(x)

is effectively the same as

f <- function(a) {
 {
   some_computation
 }(x)
}

where you seem to be expecting

{f <- function(a) {
 {
   some_computation
 }
}(x)

Got it?
  
-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



[Rd] anonymous function parsing bug?
peter dalgaard