Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the $¢ variable do in Raku?

Tags:

raku

The documentation says that there are only 3 special lexical variables ($_, $/, $!).

However, inspecting the MY:: pseudostash, it seems that a variable named also exists, and is undocumented (or at least, searching docs.raku for $¢ yields no result) (Edit: as per the accepted answer, this is actually false, it is indeed documented).

say MY::.hash;
# ==> PseudoStash.new((!UNIT_MARKER => (!UNIT_MARKER), $! => Nil, $/ => Nil, $=finish => (Mu), $=pod => [], $?PACKAGE => (GLOBAL), $_ => (Any), $¢ => Nil, &foo => &foo, ::?PACKAGE => (GLOBAL), EXPORT => (EXPORT), GLOBALish => (GLOBAL)))

sub foo {say MY::.hash}
foo();
# ==> PseudoStash.new(($! => Nil, $/ => Nil, $_ => (Any), $¢ => Nil))

$¢=5;
# The compiler doesn't complain, despite $¢ not having been declared

say $¢ 
# ==> 5

Does have any special meaning?

If it matters, I'm using rakudo v2023.12, implementing v6.d.

like image 937
biancospino Avatar asked Feb 24 '26 14:02

biancospino


1 Answers

https://docs.raku.org/type/Match

The last match is also stored in the $¢ Match object, which is lexically scoped to the regex, that is, only available from within the regular expression, as shown here

my $c;
'abc' ~~ /.$${ $c = $¢ }/;
say $c; # OUTPUT: «「c」␤»

Also see: What's the difference between $/ and $¢ in regex?

like image 123
ugexe Avatar answered Feb 27 '26 04:02

ugexe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!