From mick.jordan at oracle.com  Fri May 20 22:49:19 2016
From: mick.jordan at oracle.com (Mick Jordan)
Date: Fri, 20 May 2016 13:49:19 -0700
Subject: [Rd] identical on closures
In-Reply-To: <573F683C.6070904@oracle.com>
References: <573F683C.6070904@oracle.com>
Message-ID: <573F784F.5040704@oracle.com>

On 5/20/16 12:40 PM, Mick Jordan wrote:
> I'm confused by this:
>
> > identical(function() {}, function() {})
> [1] FALSE
>
> Yet, after loading the Matrix package (which redefines det), the 
> following is checked (in library.checkConflicts):
>
> > identical(get("det", baseenv()), get("det", asNamespace("Matrix")), 
> ignore.environment=T)
> [1] TRUE
>
> I've looked at the code in identical.c and for closures it seems to 
> compare the FORMALS and the BODY_EXPR, so why does the first example 
> not return TRUE as surely the formals and body are identical?
>
>     case CLOSXP:
>     return(R_compute_identical(FORMALS(x), FORMALS(y), flags) &&
>            R_compute_identical(BODY_EXPR(x), BODY_EXPR(y), flags) &&
>            (IGNORE_ENV || CLOENV(x) == CLOENV(y) ? TRUE : FALSE) &&
>            (IGNORE_BYTECODE || R_compute_identical(BODY(x), BODY(y), 
> flags))
>            );
>
> R-3.2.4, Mac OS X El Capitan 
Ok, I figured it out, but this is VERY unintuitive IMHO:

 > identical(attributes(function() {}), attributes(function() {}))
[1] FALSE
 >

The srcref attribute (obviously) differs.

Mick Jordan



[Rd] identical on closures
Mick Jordan