Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What does the $¢ variable do in 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).

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading