From jmc at research.bell-labs.com  Wed Sep 15 17:13:47 2004
From: jmc at research.bell-labs.com (John Chambers)
Date: Wed Sep 15 17:14:04 2004
Subject: [Rd] prototype in setClass.
References: <200409142234180547.08111512@mail.math.fu-berlin.de>
Message-ID: <41485C2B.C71C52B6@research.bell-labs.com>

It works better if you give setClass the right arguments.

In your second call,  you omitted the representation= argument, so you
need to name the prototype argument:

setClass("AtomList"
         ,contains="List"
         ,prototype =
prototype(content="Atom")                                ## would like
to specify this
         )

With this change:

R> new("AtomList")
An object of class "AtomList"
list()
Slot "uniq":
[1] FALSE

Slot "content":
[1] "Atom"

(We can probably do some bullet-proofing, since the object returned from
prototype() has a specific class, but that may have to wait until
2.0.1.)


Wolski wrote:
> 
> Hi!
> 
> To specify a prototype in the setClass declaration is a great feature.
> But prototype seems no to work for slots of the "super" class.
> eg. The following code is declaring first the super class "List".  This class has a slot "content".
> The class "AtomList" inherits from it and I would like to set content="Atom" by prototype(content="Atom").
> But after new("AtomList") is called the slot content is empty as you can see running the code below.
> 
> setClass("List"
>          ,representation(
>                          uniq="logical"
>                          ,content="character"                           ##### would like to set this when declaring the inheriting class.
>                          ,names="character")
>          ,contains="list"
>          ,prototype(uniq=FALSE)
>          )
> 
> setClass("AtomList"
>          ,contains="List"
>          ,prototype(content="Atom")                                ## would like to specify this
>          )
> 
> new("AtomList")
> 
> An object of class "AtomList"
> list()
> Slot "uniq":
> [1] FALSE
> 
> Slot "content":
> character(0)                                                            #######<-still not specified even if provided in prototype.
> 
> Slot "names":
> character(0)
> 
> Version:
> 
> R : Copyright 2004, The R Foundation for Statistical Computing
> Version 2.0.0 alpha (2004-09-14), ISBN 3-900051-07-0
> or
> R1.9.1 patched.
> 
> /E
> 
> ______________________________________________
> R-devel@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
John M. Chambers                  jmc@bell-labs.com
Bell Labs, Lucent Technologies    office: (908)582-2681
700 Mountain Avenue, Room 2C-282  fax:    (908)582-3340
Murray Hill, NJ  07974            web: http://www.cs.bell-labs.com/~jmc


[Rd] prototype in setClass.
John Chambers