On 14/01/2013, at 8:00 AM, Nil Geisweiller wrote:
>> I got sick of:
>>
>> for i in X do
>> for j in X do
>> for k in X do
>> do something
>> done
>> done
>> done
>
> To me the ideal syntax would be
>
> for i, j, k in X^3 do
> do something
> done
>
> Python comes close to that with
>
> for i, j, k in itertools.product(X, X, X):
> do something
>
> Nil
>
This is fairly easy to do*** and I was thinking of this myself,
but you should note it is not general: you cannot use that notation
to cover
for i in X do
sumi = 0;
for j in X do
sumj = 0;
for k in X do
sumk = 0;
do something
done
done
done
*** Of course this works right now:
gen iter3 (x:int, y:int, z:int) () = {
for var i in 0 upto x - 1 do
for var j in 0 upto y - 1 do
for var k in 0 upto z - 1 do
yield Some (i,j,k);
done done done
return None[int*int*int];
}
match ?i,?j,?k in iter3 (3,3,3) do
println$ i,j,k;
done
;
You could have some fun generalising iter3 to any number
of arguments polymorphically. Or you could generalise it
using dynamically using varrays or lists. Quite a bit of fun doing
that with a stream of arguments (instead of merely an array),
with recursive generators :)
--
john skaller
[email protected]
http://felix-lang.org
------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122412
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language