Thread Pythagorische Tripel
(18 answers)
Opened by Ronnie at 2008-10-19 15:57
Hi Matthias,
MatthiasW+2008-10-29 22:13:33-- statt einen Stack zu bauen kann man auch einfach die Liste "local"isieren. Da local mit lexicals nicht erlaubt ist muss mans manuell swappen. Aber deine Lösung bietet auch Möglichkeiten an, auf übergeordnete "gathers" zu "taken" , sofern man das jemals braucht. ;) Schon beim verschachteln fällt es mir schwer eine sinnvolle Anwendung zu finden... Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 ### gather schachteln? { my $list_ref=[]; sub gather (&){ my $code_ref=shift; my @list=(); my $safe=$list_ref; $list_ref=\@list; &$code_ref; $list_ref=$safe; return @list; } sub take { push @$list_ref, @_; return; } } #- simple test @x= gather{ take [$_] for (1..3) }; print Dumper \@x; #- nested test @x=(); @x= gather{ take gather{ my $x=$_; take [$_,$x] for (1..$x) } for (1..5); }; print Dumper \@x; me and my writeups
|