On Sun, 04 Jan 2009 14:19:15 -0500, Uri Guttman wrote: >>>>>> "m" == moritz <mor...@casella.faui2k3.org> writes: > m> But I think that a .perl()ification as ("blue", "light", "hayard",) would > m> make much more sense, because simple thing like > > m> @a.push eval(@b.perl) > > m> would then DWIM. > > for your def of DWIM. i can see wanting an anon array to be pushed onto > @a building up a structure.
That would be easily achievable if we made the change I'm suggesting, so that C<@a.perl> emitted round brackets. This is how you would clone an array, as Moritz wants to do: m...@edward:~/perl/6$ cat uri1 #!/home/msl/bin/perl6 # Imagine that @b.perl has produced this: my $p = "('blue', 'light', 'hazard')"; my @a; @a.push(eval $p); .say for @a; m...@edward:~/perl/6$ ./uri1 blue light hazard m...@edward:~/perl/6$ Adding a single backslash before `eval' pushes an anonymous array on to @b, as you envisage wanting to do: m...@edward:~/perl/6$ cat uri2 #!/home/msl/bin/perl6 # Imagine that @a.perl has produced this: my $p = "('blue', 'light', 'hazard')"; my @b; @b.push(\eval $p); .say for @b; m...@edward:~/perl/6$ ./uri2 blue light hazard m...@edward:~/perl/6$ > a more useful example would be serializing data trees. if you dump @b > with .perl do you want the current dumper output of a anon array or your > list of values? when serializing a tree, you must get the ref version so > that is the common and default usage. your version isn't DWIMmy there at > all. I think Perl 6's automatic reference-taking (though we don't call them references any more) solves that problem for us. If you say my @c = eval '(1, 2, 3)'; then @c has three elements. If you say my $c = eval '(1, 2, 3)'; then Perl constructs (if I've got the Perl 6 lingo right) an Array object and stores it in $c. So the round brackets DTRT whether you're storing into an array like @c or into a scalar like $c. I'd like to use your example of serialising and unserialising to suggest that the current behaviour is wrong: m...@edward:~/perl/6$ cat serialise #!/home/msl/bin/perl6 my @a = <blue light hazard>; @a.perl.say; m...@edward:~/perl/6$ cat unserialise #!/home/msl/bin/perl6 my $p = =$*IN; my @a = eval $p; for (@a) { .say } m...@edward:~/perl/6$ ./serialise | ./unserialise blue light hazard m...@edward:~/perl/6$ We serialised an array of three elements; we got back an array containing just one. Round brackets would have solved that. (Actually, we don't need any brackets at all, because Perl 6's list constructor is a comma, not a set of brackets. But round brackets would be no-ops, and they arguably make the output more human-readable.) Markus