For p6, they already moved one step ahead with separation of $thing x $count being a scalar-repeat(*) and $thing xx $count being a list-repeat(*).

* My terms, probably incorrect.

Looking at the output from -MO=concise for various uses of x, it looks like the optree has enough information in it to allow the repeat operator (or maybe the peep-hole optimiser) to determine whether the list being repeated contains a single 'active' element. Where 'active' is basically anything that isn't a constant or simple scalar: an srefgen; a function call etc. and have a special case for calling that active element iterator wise. The problem is it would the require some way to indicate when you really did want the list-wise replication of a single actively generated list item, and would break all existing uses.

So, I guess the question is: Is there any syntactically nice way of indicating the difference between my @data = rand xx 1000; meaning I want a thousand different random numbers and my @data = rand xx 1000; I want a thousand copies of the same random number.

I toyed with my @data = rand xxx 1000; for the former, but that would probably get every site displaying perl code using it blocked under "18 USC 2257", which might not be a good idea :)

Another possibility is that my @a = { ... } xx 1000; would call the anon. block (or subref) 1000 times, but whether that is sufficiently clearer than my @a = map{ ... } 1 .. 1000; to be worth the cruft is the kind of decision that LW gets right whilst the rest of us are still uming annd ahhing.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon

In reply to Re^3: Using x to build data structures considered harmful by BrowserUk
in thread Using x to build data structures considered harmful by dws

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.