in reply to Raku: * v. $_ (asterisk v. the topic variable)
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 | סתם עוד האקר של פרל, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Raku: * v. $_ (asterisk v. the topic variable)
by 7stud (Deacon) on Feb 19, 2024 at 14:34 UTC | |
by raiph (Deacon) on Feb 20, 2024 at 02:18 UTC | |
by 7stud (Deacon) on Feb 20, 2024 at 21:54 UTC |