From sfalcon at fhcrc.org  Wed Sep 27 17:34:38 2006
From: sfalcon at fhcrc.org (Seth Falcon)
Date: Wed, 27 Sep 2006 08:34:38 -0700
Subject: [Rd] S4 accessors
In-Reply-To: <451A8B95.8050406@r-project.org> (John Chambers's message of "Wed,
	27 Sep 2006 10:32:53 -0400")
References: <1159230049.7161.132.camel@iron.psg.net>
	<m2mz8n2prs.fsf@ziti.local> <1159291414.7161.143.camel@iron.psg.net>
	<m21wpyzfph.fsf@ziti.local> <1159299299.7161.239.camel@iron.psg.net>
	<451A8B95.8050406@r-project.org>
Message-ID: <m24putmigh.fsf@ziti.local>

John Chambers <jmc at r-project.org> writes:

> There is a point that needs to be remembered in discussions of
> accessor functions (and more generally).
>
> We're working with a class/method mechanism in a _functional_
> language.  Simple analogies made from class-based languages such as
> Java are not always good guides.
>
> In the example below, "a function foo that only operates on that
> class" is not usually a meaningful concept in R.   

If foo is a generic and the only method defined is for class Bar, then
the statement seems meaningful enough?

> Functions are first-class objects and in principle every function
> should have a "function", a purpose.  Methods implement that purpose
> for particular combinations of arguments.
>
> Accessor functions are therefore a bit anomalous.  

How?  A given accessor function has the purpose of returning the
expected data "contained" in an instance.  It provides an abstract
interface that decouples the structure of the class from the data it
needs to provide to users.

The anomaly, is IMO, a much larger challenge with generic function
based systems.  When the same name for a generic is used in different
packages, you end up with a masking problem.  This scenario is
unavoidable in general, but particularly likely, for accessors.  As S4
becomes more prevalent, I suspect that '<pkg>::foo' is going to become
a required idiom for interactive use (other options are available for
package code).

+ seth




[Rd] S4 accessors
Seth Falcon