From gmbecker at ucdavis.edu  Fri May 20 23:00:02 2016
From: gmbecker at ucdavis.edu (Gabriel Becker)
Date: Fri, 20 May 2016 14:00:02 -0700
Subject: [Rd] identical on closures
In-Reply-To: <573F784F.5040704@oracle.com>
References: <573F683C.6070904@oracle.com>
	<573F784F.5040704@oracle.com>
Message-ID: <CADwqtCPXRLFAOMABi3n-CFk4kGZ7nEX9YXNwMhYrkJjg0c9bLA@mail.gmail.com>

Specifically, the srcfile attribute of the srcref attribute of the two
instances of the functions contain different environments, AFAICT.
Environments are compared only by exact pointer, so this forces return
FALSE.

Snippets from .Internal(inspect(x)) and .Internal(inspect(y)):

@cca008 03 CLOSXP g0c0 [MARK,NAM(2),ATT]
FORMALS:
  @604b58 00 NILSXP g0c0 [MARK,NAM(2)]
BODY:
  @cc9650 06 LANGSXP g0c0 [MARK,ATT]
    @604998 01 SYMSXP g0c0 [MARK,LCK,gp=0x5000] "{" (has value)
  ATTRIB:
    @cc9570 02 LISTSXP g0c0 [MARK]
      TAG: @60dd70 01 SYMSXP g0c0 [MARK,LCK,gp=0x4000] "srcref" (has value)
      @15a65d8 19 VECSXP g0c1 [MARK] (len=1, tl=0)
    @10f3dd0 13 INTSXP g0c3 [OBJ,MARK,ATT] (len=8, tl=0) 1,15,1,15,15,...
    ATTRIB:
      @cc9618 02 LISTSXP g0c0 [MARK]
        TAG: @60dde0 01 SYMSXP g0c0 [MARK,NAM(2),LCK,gp=0x4000]
*"srcfile" *(has
value)
        *@cc97d8* 04 *ENVSXP* g0c0 [OBJ,MARK,NAM(2),ATT] <0xcc97d8>




@cca8a8 03 CLOSXP g0c0 [MARK,NAM(2),ATT]
FORMALS:
  @604b58 00 NILSXP g0c0 [MARK,NAM(2)]
BODY:
  @cc9eb8 06 LANGSXP g0c0 [MARK,ATT]
    @604998 01 SYMSXP g0c0 [MARK,LCK,gp=0x5000] "{" (has value)
  ATTRIB:
    @cc9da0 02 LISTSXP g0c0 [MARK]
      TAG: @60dd70 01 SYMSXP g0c0 [MARK,LCK,gp=0x4000] "srcref" (has value)
      @15a6488 19 VECSXP g0c1 [MARK] (len=1, tl=0)
    @10f3c68 13 INTSXP g0c3 [OBJ,MARK,ATT] (len=8, tl=0) 1,15,1,15,15,...
    ATTRIB:
      @cc9e80 02 LISTSXP g0c0 [MARK]
        TAG: @60dde0 01 SYMSXP g0c0 [MARK,NAM(2),LCK,gp=0x4000] *"srcfile"*
(has value)
       * @cc9ef0* 04 *ENVSXP* g0c0 [OBJ,MARK,NAM(2),ATT] <0xcc9ef0>


~G

On Fri, May 20, 2016 at 1:49 PM, Mick Jordan <mick.jordan at oracle.com> wrote:

> 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
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



-- 
Gabriel Becker, PhD
Associate Scientist (Bioinformatics)
Genentech Research

	[[alternative HTML version deleted]]



[Rd] identical on closures
Gabriel Becker