phylanx icon indicating copy to clipboard operation
phylanx copied to clipboard

Feature: Use decorator within a class

Open diehlpk opened this issue 5 years ago • 2 comments

I was wondering if we can get this example to work in a near future

from phylanx import Phylanx


class test:
    
    n = 0
    
    @Phylanx
    def __init__(self,n):
        self.n = n
        
    @Phylanx
    def do(self,m):
        self.n += m 
    
    
if __name__ == "__main__":
    
    t = test(10)
    
    t.do(10) 

Or at least make some comment in the Readme that this is not supported yet

diehlpk avatar Sep 24 '20 17:09 diehlpk

This is not supported (yet), as we don't support classes at all.

hkaiser avatar Sep 24 '20 17:09 hkaiser

We should implement this instead:

from phylanx import Phylanx

@Phylanx
class test:
    
    n = 0
    
    def __init__(self,n):
        self.n = n
        
    def do(self,m):
        self.n += m 

if __name__ == "__main__":
    t = test(10)
    t.do(10) 

hkaiser avatar Oct 12 '20 00:10 hkaiser