Hello 7stud,

Consider the following:

16:46 >raku -e "for 1 .. * { qq[$_ is { $_.^name }].put; last if $_ >= + 3; }" 1 is Int 2 is Int 3 is Int 16:46 >

$_ is the topic variable which, as in Perl, acts like a pronoun: we can read the code as “for each value from 1 to infinity, print it and its type, ...” The topic variable $_ is documented in https://docs.raku.org/language/variables#The_$__variable.

The star, on the other hand, is not a variable, but rather an object — specifically, an instance of Raku’s built-in Whatever class. Its meaning depends on the context in which it is used. In this case it is being used as the end-point of a range, so its meaning is defined by the Range class, which interprets it as Inf (infinity). This use of the star in Raku is documented in https://docs.raku.org/type/Whatever.

So although $_ and * can sometimes be used interchangeably, they are in fact quite different things.

Hope that helps,

Athanasius <°(((><contra mundum סתם עוד האקר של פרל,


In reply to Re: Raku: * v. $_ (asterisk v. the topic variable) by Athanasius
in thread Raku: * v. $_ (asterisk v. the topic variable) by 7stud

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.