<p>I'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, "Doug Blank" <<a href="mailto:doug.blank@gmail.com">doug.blank@gmail.com</a>> 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 <<a href="mailto:dinov@microsoft.com">dinov@microsoft.com</a>> wrote:<br>
><br>
><br>
> Jeff wrote:<br>
>> IronPython's conversion code is, um, interesting -- Dino might understand it all,<br>
>> but I don't know if anyone else does -- so it's possible two different sets of<br>
>> conversions are being chosen. Now, this<br>
>> *shouldn't* be the case, but it's my hypothesis.<br>
><br>
> Ha! Overload resolution is like Conway's game of life, you can know the rules,<br>
> but knowing the behavior is another time entirely... Luckily this doesn't so much deal with<br>
> that rather than how our IList<T> wrapper is implemented in ConversionWrappers.cs.<br>
> The indexer is just doing a C# cast from the value to the T type. That could easily<br>
> be changed to do a full Python conversion.<br>
><br>
> I think doing an is check first and only doing the conversion if it's not already the proper<br>
> type would be an alright change. But it could be a little surprising in that sometimes you<br>
> could get a new instance each time you access an element (e.g. a new delegate could be<br>
> 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<dynamic> functions)<br>
{<br>
foreach (dynamic function in functions) {<br>
Func<object> func =<br>
IronPython.Runtime.Converter.Convert<Func<object>>(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<object> [] functions) {<br>
foreach (Func<object> function in functions) {<br>
function();<br>
}<br>
}<br>
public void function2(IList<Func<object>> functions) {<br>
foreach (Func<object> function in functions) {<br>
function();<br>
}<br>
}<br>
<br>
[I'll put that in the issue tracker and y'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'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 "thunk" in Scheme lingo) and then using the<br>
first example, but we'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>