
B.6. THE R LIST TYPE 303
So now we have two objects of a class we’ve chosen to name ”employee”.
Note the quotation marks.
We can write class generic functions:
> print . employee <− function ( wrkr ) {
+ cat ( wrkr$name , ”\n” )
+ cat ( ” s a l a r y ” , wrkr$ s al a ry , ”\n” )
+ cat ( ” union member” , wrkr$union , ”\n” )
+ }
> print ( j )
Joe
s a l a r y 55000
union member TRUE
> j
Joe
s a l a r y 55000
union member TRUE
What just happened? Well, print() in R is a generic function, meaning
that it is just a placeholder for a function specific to a given class. When we
printed j above, the R interpreter searched for a function print.employee(),
which we had