>>>>> "ML" == Markus Laker <u20090103.20.mla...@spamgourmet.com> writes:

  ML> Adding a single backslash before `eval' pushes an anonymous array on to
  ML> @b, as you envisage wanting to do:

  ML> # Imagine that @a.perl has produced this:
  ML> my $p = "('blue', 'light', 'hazard')";

  ML> my @b;
  ML> @b.push(\eval $p);

but that is manual code. what about a larger tree?

  >> 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.


  ML> I think Perl 6's automatic reference-taking (though we don't call them
  ML> references any more) solves that problem for us.

  ML> If you say

  ML> my @c = eval '(1, 2, 3)';

  ML> then @c has three elements.  If you say

  ML> my $c = eval '(1, 2, 3)';

  ML> then Perl constructs (if I've got the Perl 6 lingo right) an Array object
  ML> and stores it in $c.  So the round brackets DTRT whether you're storing
  ML> into an array like @c or into a scalar like $c.

that fails with nested arrays. we don't want them to flatten.

my $c = eval '(1, (4, 5), 3)';

will that work as you envision? in perl5 with [] it works fine. i know
there are contexts that flatten and others that don't. but a larger tree
with assignments like that are harder to read IMO as lists inside lists
are not nesting but flattening in p5 all the time.

  ML> We serialised an array of three elements; we got back an array containing
  ML> just one.  Round brackets would have solved that.  (Actually, we don't
  ML> need any brackets at all, because Perl 6's list constructor is a comma,
  ML> not a set of brackets.  But round brackets would be no-ops, and they
  ML> arguably make the output more human-readable.)

try that again with my example above. in p5 the structure would be this:

my $c = [1, [4, 5], 3] ;

how should .perl serialize that so that eval will give back the same
structure? unless () are nesting and not flattening then you can't do it
without a \() which is longer (and uglier IMO than []).

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

Reply via email to