<div class="gmail_quote">On 21 December 2011 17:51, Ian Kelly <span dir="ltr"><<a href="mailto:ian.g.kelly@gmail.com" target="_blank">ian.g.kelly@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div>On Wed, Dec 21, 2011 at 9:48 AM, Joshua Landau<br>
<<a href="mailto:joshua.landau.ws@gmail.com" target="_blank">joshua.landau.ws@gmail.com</a>> wrote:<br>
> functions, that before you were doing on a single item.<br>
> BEFORE:<br>
> item = foreignfunc1(item)<br>
> item = foreignfunc2(item)<br>
> item = foreignfunc3(item)<br>
><br>
> NOW (your method):<br>
> item = ElementwiseProxy(item)<br>
> item = foreignfunc1(item)<br>
> item = foreignfunc2(item)<br>
> item = foreignfunc3(item)<br>
> item = list(item)<br>
<br>
</div>Shouldn't that be:<br>
<br>
item = ElementwiseProxy(item)<br>
item = item.apply(foreignfunc1)<br>
item = item.apply(foreignfunc2)<br>
item = item.apply(foreignfunc3)<br>
item = list(item)</blockquote><div><br></div><div>I was under the impression that these were meant to be interchangeable. This is because functions are just wrappers to non-functions, really.</div><div><br></div><div>>>> from elementwise import ElementwiseProxy as P</div>


<div>>>> (lambda x:x+[1])(P([[0],[0],[0]]))</div><div>[0, 1], [0, 1], [0, 1]</div><div><br></div><div>If we have to use .apply, we might as well use map :P.</div><div><br></div><div>Note that "len" and "dir" crash.</div>


<div><br></div><div><b><u>Here is a perfect example:</u></b></div><div><div>>>> int(P(["1","2","3"]))</div><div>Traceback (most recent call last):</div><div>  File "<stdin>", line 1, in <module></div>


<div><b>TypeError: __int__ returned non-int (type ElementwiseProxy)</b></div></div><div><br></div><div>It's elementwise, <b>but that breaks it.</b> An elementwise operator wouldn't have these problems.</div><div>

<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
> You might think your method works. But what if foreignfunc is "str"? And you<br>
> can't blacklist functions. You can't say everything works bar A, B and C.<br>
> What if you get: "lambda x:str(x)"? You can't blacklist that. That makes the<br>
> ElementwiseProxy version buggy and prone to unstable operation. If it's<br>
> consistent, fine. But it's not.<br>
<br>
</div>I'm not sure I understand this criticism.  There is no "blacklisting"<br>
going on that I am aware of.  The behavior seems consistent to me:<br>
<br>
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit<br>
(Intel)] on win32<br>
Type "help", "copyright", "credits" or "license" for more information.<br>
>>> from elementwise import *<br>
>>> ewp = ElementwiseProxy(range(5))<br>
>>> str(ewp)<br>
'0, 1, 2, 3, 4'<br>
>>> (lambda x: str(x))(ewp)<br>
'0, 1, 2, 3, 4'<br>
>>> ewp.apply(str)<br>
'0', '1', '2', '3', '4'<br>
>>> ewp.apply(lambda x: str(x))<br>
'0', '1', '2', '3', '4'<br>
<br>
All of which is exactly what I expected to get.<br></blockquote><div><br></div><div>Again, str(x) in this context is an outlier. It's one of the exceptions to the rule of applying functions = elementwise.</div></div>