On 21 December 2011 17:51, Ian Kelly <ian.g.ke...@gmail.com> wrote: > On Wed, Dec 21, 2011 at 9:48 AM, Joshua Landau > <joshua.landau...@gmail.com> wrote: > > functions, that before you were doing on a single item. > > BEFORE: > > item = foreignfunc1(item) > > item = foreignfunc2(item) > > item = foreignfunc3(item) > > > > NOW (your method): > > item = ElementwiseProxy(item) > > item = foreignfunc1(item) > > item = foreignfunc2(item) > > item = foreignfunc3(item) > > item = list(item) > > Shouldn't that be: > > item = ElementwiseProxy(item) > item = item.apply(foreignfunc1) > item = item.apply(foreignfunc2) > item = item.apply(foreignfunc3) > item = list(item)
I was under the impression that these were meant to be interchangeable. This is because functions are just wrappers to non-functions, really. >>> from elementwise import ElementwiseProxy as P >>> (lambda x:x+[1])(P([[0],[0],[0]])) [0, 1], [0, 1], [0, 1] If we have to use .apply, we might as well use map :P. Note that "len" and "dir" crash. *Here is a perfect example:* >>> int(P(["1","2","3"])) Traceback (most recent call last): File "<stdin>", line 1, in <module> *TypeError: __int__ returned non-int (type ElementwiseProxy)* It's elementwise, *but that breaks it.* An elementwise operator wouldn't have these problems. > You might think your method works. But what if foreignfunc is "str"? And > you > > can't blacklist functions. You can't say everything works bar A, B and C. > > What if you get: "lambda x:str(x)"? You can't blacklist that. That makes > the > > ElementwiseProxy version buggy and prone to unstable operation. If it's > > consistent, fine. But it's not. > > I'm not sure I understand this criticism. There is no "blacklisting" > going on that I am aware of. The behavior seems consistent to me: > > Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> from elementwise import * > >>> ewp = ElementwiseProxy(range(5)) > >>> str(ewp) > '0, 1, 2, 3, 4' > >>> (lambda x: str(x))(ewp) > '0, 1, 2, 3, 4' > >>> ewp.apply(str) > '0', '1', '2', '3', '4' > >>> ewp.apply(lambda x: str(x)) > '0', '1', '2', '3', '4' > > All of which is exactly what I expected to get. > Again, str(x) in this context is an outlier. It's one of the exceptions to the rule of applying functions = elementwise.
-- http://mail.python.org/mailman/listinfo/python-list