<p>I&#39;m just glad to see more people engaged in using IronPython!</p>
<p>Thanks,</p>
<p>Slide</p>
<div class="gmail_quote">On Mar 17, 2012 5:16 PM, &quot;Doug Blank&quot; &lt;<a href="mailto:doug.blank@gmail.com">doug.blank@gmail.com</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Sat, Mar 17, 2012 at 6:51 PM, Dino Viehland &lt;<a href="mailto:dinov@microsoft.com">dinov@microsoft.com</a>&gt; wrote:<br>
&gt;<br>
&gt;<br>
&gt; Jeff wrote:<br>
&gt;&gt; IronPython&#39;s conversion code is, um, interesting -- Dino might understand it all,<br>
&gt;&gt; but I don&#39;t know if anyone else does -- so it&#39;s possible two different sets of<br>
&gt;&gt; conversions are being chosen. Now, this<br>
&gt;&gt; *shouldn&#39;t* be the case, but it&#39;s my hypothesis.<br>
&gt;<br>
&gt; Ha!  Overload resolution is like Conway&#39;s game of life, you can know the rules,<br>
&gt; but knowing the behavior is another time entirely...  Luckily this doesn&#39;t so much deal with<br>
&gt; that rather than how our IList&lt;T&gt; wrapper is implemented in ConversionWrappers.cs.<br>
&gt; The indexer is just doing a C# cast from the value to the T type.  That could easily<br>
&gt; be changed to do a full Python conversion.<br>
&gt;<br>
&gt; I think doing an is check first and only doing the conversion if it&#39;s not already the proper<br>
&gt; type would be an alright change.  But it could be a little surprising in that sometimes you<br>
&gt; could get a new instance each time you access an element (e.g. a new delegate could be<br>
&gt; created each time).<br>
<br>
Thanks for the hints! I was able to get the functionality I was<br>
seeking. Here is the relevant code I ended up with:<br>
<br>
        public static List doTogether (IList&lt;dynamic&gt; functions)<br>
        {<br>
                foreach (dynamic function in functions) {<br>
                        Func&lt;object&gt; func =<br>
IronPython.Runtime.Converter.Convert&lt;Func&lt;object&gt;&gt;(function);<br>
        ...<br>
<br>
I need to do some more testing to make sure that this will always do<br>
the right thing. For example, I would want this function to be able to<br>
take, say, an IronRuby function and coerce it into the correct type as<br>
well.<br>
<br>
It does seem like these two functions should behave similarly:<br>
<br>
public void function1(params Func&lt;object&gt; [] functions) {<br>
    foreach (Func&lt;object&gt; function in functions) {<br>
        function();<br>
    }<br>
}<br>
public void function2(IList&lt;Func&lt;object&gt;&gt; functions) {<br>
    foreach (Func&lt;object&gt; function in functions) {<br>
        function();<br>
    }<br>
}<br>
<br>
[I&#39;ll put that in the issue tracker and y&#39;all can decide what the best<br>
thing to do is.]<br>
<br>
FYI, the interface I was working on was an easy way for users to run<br>
code in parallel (using Threads from behind). The function<br>
doTogether() (based on an Alice block of the same name) now allows the<br>
following:<br>
<br>
doTogether(f1, f2, ...): will run f1(), f2() at the same time and<br>
return their results in a list<br>
doTogether([f1, f2, ...], arg): will run f1(arg), f2(arg) at the same<br>
and return their results in a list<br>
doTogether(f1, [arg1, arg2, ...]): will run f1(arg1), f1(arg2) at the<br>
same time and return their results in a list<br>
doTogether([f1, arg1, ...], [f2, arg2, ...], ...): will run f1(arg1),<br>
f2(arg2) at the same time and return their results in a list<br>
<br>
I&#39;ve used this in class to compose music (each function is an<br>
instrument), robot dancing (each argument is a robot), and parallel<br>
computation, among other mundane uses (such as initialize a bunch of<br>
serial ports in parallel). (The last example there would look better<br>
with lambdas (making a &quot;thunk&quot; in Scheme lingo) and then using the<br>
first example, but we&#39;re trying to allow some flexibility in when we<br>
must introduce additional concepts.) Full code available in the Myro<br>
library [1].<br>
<br>
Thanks again!<br>
<br>
-Doug<br>
<br>
[1] - <a href="http://svn.cs.brynmawr.edu/viewvc/Calico/trunk/modules/Myro/Myro.cs" target="_blank">http://svn.cs.brynmawr.edu/viewvc/Calico/trunk/modules/Myro/Myro.cs</a><br>
_______________________________________________<br>
Ironpython-users mailing list<br>
<a href="mailto:Ironpython-users@python.org">Ironpython-users@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/ironpython-users" target="_blank">http://mail.python.org/mailman/listinfo/ironpython-users</a><br>
</blockquote></div>