[Rd] proto and baseenv()
Peter Danenberg
pcd at roxygen.org
Fri Feb 26 03:23:22 CET 2010
> > I think you are looking for a different object model than proto
> > offers. There aren't many languages that offer the prototype object
> > model.
>
> Yes, your probably right---I don't have much experience using the
> prototype model. This is the way I expected it to work:
>
> > z <- 1
> > p <- proto(expr={a <- z})
> > p$a
> [1] 1
> > p$z
> Error in get(x, env = this, inherits = inh) : variable "z" was not found
Which is exactly how it should work! Namespace pollution is orthogonal
to the specific object model, and Duncan's assertion about the
prevalence of prototypes is a red herring.
Here's how it works in Scheme, for instance, using Neil van Dyke's
Prototype-Delegation package:[1]
#;1> (use protobj)
#;2> (define z 1)
#;3> (define a (%))
#;4> (! a a z)
#;5> (? a a)
1
#;6> (? a z)
Error: Object has no such slot:
#<object>
z
Just like one would expect! And since protobj is based on self,
Ungar-Smith's original prototype system,[2] I suspect that self
behaves similarly.
Footnotes:
[1] http://www.neilvandyke.org/protobj/
[2] http://research.sun.com/self/papers/self-power.html
More information about the R-devel
mailing list