On Mon, Aug 09, 2021 at 01:00:52PM -0700, Joseph Brenner wrote:
> There's this much:
> 
> https://docs.raku.org/language/variables#index-entry-$$CIRCUMFLEX_ACCENT
> 
> > If you have self-declared a parameter using $^a once, you may refer to it 
> > using only $a thereafter.
> 
> But it doesn't go anywhere near far enough.   You *had better* to
> refer to it as $a or you'll get some very weird behavior, though only
> under some circumstances.

Just to clarify (because I'm not sure this is clear yet):

You get "weird" behavior if you try to use it in the $^a form in a nested 
block, because the language treats any caret variables in the nested block as 
being part of the signature definition for the nested block.

So, going to the original "if" example, writing

   { 
     if ($^a eq $^b) {
       "$^a";
     } else {
       "$^a & $^b";
     }
   }

is akin to writing

   -> $a, $b {
     if ($a eq $b) -> $a {
       "$a";
     } else -> $a, $b {
       "$a & $b";
     }
   }

Each of the nested blocks is effectively defining a local $a (and $b), and the 
error is because the else clause sends only one argument to the block where two 
are expected.

The if statement and its clauses receive the result of the comparison as 
arguments to the nested blocks, if I remember correctly.  This is why "else" 
sends only one argument to its nested block.

Hope this helps a bit,

Pm
  

Reply via email to