I didn't state my point well. What you appear to be suggesting is a special case of what given does: topicalize something so you can both test and reuse it.

And also return it. It seems to me that given would require an extra layer in the form another block around it. And it is a far general tool and to use it for this purpose would require to lose any conciseness and terseness that was being sought in the first place. What I'm thinking of is a specialized one, just less specialized than say C<||> or C<//>.

I say this notwithstanding that some time ago I mused on a similar (not identical) notion. It didn't generate much excitement, either.

Well, I ++'ed that, as well this, for sympathy. Actually I kinda liked the idea, but for the bare operators that really do not fit well both in 5 and 6.

Can you write a function that would do what you want?

I'm not really sure: you can certainly define operators, which is fun. In fact finally operators are nothing other than regular functions. My favourite example (basically, the only one I'm familiar with), which you can run in pugs already is:

pugs> sub postfix:<!> (Int $n) { [*] 1..$n } undef pugs> say $_! for ^5 1 1 2 6 24 undef

But I don't know if it will be possible to create shortcutting operators, as I also wrote in the root node. Well, Perl 6 is supposed to have macros, and perhaps it will be doable with them, but I don't know anything about macros myself. Or else, since it will eventually have a grammar modifiable at runtime, one may act on that. (Not really for the faint of heart I suppose.)


In reply to Re^4: [Perl 6] Generalized shortcutting C<||>? by blazar
in thread [Perl 6] Generalized shortcutting C<||>? by blazar

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.