Skip to content
Prev 22096 / 63424 Next

generics for primitive functions

Yes, I figured I might have entered the forbidden zone (one hint was  
that I had to set the group method to achieve my goal -- an attempt  
to directly set a method for the 'sqrt' function was frustrated in  
the manner you suggest).  I have two followup questions and a request:

(i) Should I expect that the fix will be to seal group methods for  
groups that contain primitive functions and signatures comprising  
only basic data types, or that group methods will remain unsealed  
(and thus still work as desired for non-primitive underliers) and  
some other block applied?

(ii) In "How Methods Work" (pg. 8), you write: "So long as  
computations access the generic function through getGeneric(), most  
computations should be unaffected."  I took this as a suggestion that  
calls like getGeneric("sqrt")(4) were the suggested way to operate  
with primitives under S4.  What does it really mean?

Now the request (with some explanation).  I am not really interested  
in redefining primitives for class 'numeric.'  What I really want to  
do is define working non-primitive variants of primitives for class  
'expression'.  I have already done this for a class 'Expression'  
which contains 'expression' as you suggest, but I have been somewhat  
frustrated to go through the formality of dealing with a "custom"  
class for this purpose (as it adds unnecessary bulk and coercion to  
my code).  Since AFAIK none of the primitives in the 'Ops' or 'Math'  
groups work for objects of class 'expression' anyway, I don't see  
what purity we are retaining by sealing the methods on these  
functions for signatures comprising only objects of class 'expression'.

I'd like to request (as a feature change) that these methods be  
unsealed for signatures comprising only objects of class  
'expression'.  More broadly, I think it would be nice to unseal  
methods for primitive functions on all signatures for which the  
primitive would produce an error.  Sealing things that don't work is  
slightly cruel.  Perhaps a 'sealedPrimitives' option that the  
efficiency guys could check and freaks like me (who want to make 2+2  
= 3) could uncheck would be the simplest solution.  Of course I make  
this request humbly -- I have no idea what might be the cost in code  
of the discrimination I am requesting.

Franklin
On Sep 23, 2006, at 3:35 AM, John Chambers wrote: