-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Why not let people set their own topic variable (characters)? Something like:
♢=$_;
my @circles = map { Circle.new: :radius(♢) }, @radii;♢
WHITE DIAMOND SUIT
Unicode: U+2662, UTF-8: E2 99 A2
♦︎
BLACK DIAMOND SUIT
Unicode: U+2666 U+FE0E, UTF-8: E2 99 A6 EF B8 8E
Maybe people do have an aversion to sigils (I don't). Many people (also) complained about Perl using too many "implicit" references to $_ topic variable, which were made explicit in Perl6/Raku. However this:
- had the positive effect of regularizing the Perl6/Raku codebase (making it more accessible to new users), while
- having the negative effect of making Perl6/Raku look more "line-noisy" because now
$_started popping up everywhere.
Sigil-less variables are available in Raku, but $_ can't be changed. So to make Raku less "line-noisy" (due to the topic variable), let programmers set the topic variable to their favorite character:
♟=$_;
my @circles;
for @radii {
@circles.append: Circle.new( radius => ♟ );
}♟
chess pawn
Unicode: U+265F, UTF-8: E2 99 9F
Now...let's backtrack a bit.
Aren't there other (pre-Perl) languages that use a topic variable? Do they default to $_?
So maybe non-Perl programmers have seen $_ in their language?
Can we teach a tiny bit on the Raku Home Page, such as extolling the virtues of having functions default to the topic variable?
AND CAN WE MAKE IT PRETTIER?
AND CAN WE LET PEOPLE PERSONALIZE THEIR EXPERIENCE,
LIKE 😀 AS A TOPIC VARIABLE?
OR ⚽️?
Thank you for your attention.
[ Below is a reference to the use of :$^radius variable on the Raku Home Page, feel free to ignore ].
Now, I love @thoughtstream 's example (see Raku/raku.org#272 (comment)), but I've never felt that way about sigils. To me they are a necessary evil. You can add any function to the Raku language that you want, and you're not going to cause a parsing error because variables are sigiled (as opposed to awk and many other languages, I'm sure).
Finally, the issue of :radius($_) not :$^radius ...
Brilliant code is ...brilliant. But do we turn off new users by:
- not teaching them about the topic variable, and
- using a construct that could be confusing to them?
I myself have used $^a and $^b for sorting, but never :$^radius or similar. I can say when we reviewed the code in the Raku Study Group (2025-09-07 @ 1pm California time), there were attendees (other than me) who were a little surprised._