[Python-ideas] (no subject)

Yongsheng Cheng cyscoyote at gmail.com
Tue May 31 09:04:11 EDT 2016


to begin with: i a deep python fun
i want to suguest python a feature to support Fuctional Program :,here is
the toy code  i need a more powerful decrote in moudle functools instead of
functools.partial,thanks do you think it is a nice idea?
waitting for your reply

def minpara(func_1,args):
     num=0
     try:
         func_1(*args)
     except Exception as error:
         num,given=re.findall(r'\d+',str(error))[:2]
     if num:
        #return int(num),int(given)
         return (num,given)
     else:
         #return func(*args)
         return (0,0)

def curried(func):
    #@wraps(func)
    def new_func(*args):
        num,given=minpara(func,args)
        #print num,given
        if (num,given)==(0,0):
            return func(*args)
        else:
            return curried(functools.partial(func,*args))
    return new_func
@curried
def sun_1(a,b,c):
    return a+b+c
@curried
def sun_2(a,b,c):
     return a*b*c
if __name__=="__main__":
    print sun_2(1,)(2)(44)
    print sun_1(1,)(2)(44)
    print sun_2(1,2)(23)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160531/6972b75c/attachment.html>
-------------- next part --------------
def minpara(func_1,args):
     num=0
     try:
         func_1(*args)
     except Exception as error:
         num,given=re.findall(r'\d+',str(error))[:2]
     if num:
        #return int(num),int(given)
         return (num,given)
     else:
         #return func(*args)
         return (0,0)

def curried(func):
    #@wraps(func)
    def new_func(*args):
        num,given=minpara(func,args)
        #print num,given
        if (num,given)==(0,0):
            return func(*args)
        else:
            return curried(functools.partial(func,*args))
    return new_func
@curried   
def sun_1(a,b,c):
    return a+b+c
@curried
def sun_2(a,b,c):
     return a*b*c
if __name__=="__main__":
    print sun_2(1,)(2)(44)
    print sun_1(1,)(2)(44)
    print sun_2(1,2)(23)


More information about the Python-ideas mailing list