Via pretzel logic I've concluded that:
- You may have carefully written your Q to trick us, and you will reveal the truth if we correctly solve the riddle.
Or (a tad more likely perhaps... ):
- Adopting that mindset will help us all -- you, readers, answerers -- have fun as we try to solve the riddle inherent in your sincere Q even if you weren't planning to make this fun...
Either way, please read this answer and let me know if it contributes to solving the riddle. TIA. :)
I'm missing something aren't I but what?
Perhaps this is a key for solving the riddle: we're supposed to ask ourselves "What has Keith deliberately missed out of the Q?".
Of course, if this is so, the first thing you've omitted is that it's a riddle. In which case, major kudos! And if it's not an intentional riddle, well, it's still a riddle, so kudos anyway, and let's try solve it!
@codesection's answer points at perhaps the strongest clue. While you didn't write a minimal reproducible example, you did write the sub
definition code, and you did say you'd written $private=False
.
So let's presume you literally wrote that sub
definition and you literally wrote $private=False
.
Furthermore, that:
with $private=False
invoking 'named' still prints 'Official business!' whereas I thought there should be no output generated.
means there was some output generated in all cases.
Anyhoo, how can all of these things be true at the same time?
These are compile-time errors:
sub named( :official( $private = True ) ) { "Official business!" if $private }
sub named( :official( $private = False ) ) { "Official business!" if $private }
So is this:
$private = False;
unless there was a prior my $private...
.
And this:
sub named( :official( $private ) ) {
$private = True;
"Official business!" if $private
}
named;
yields Cannot assign to a readonly variable or a value
(currently at runtime) because, by default, parameters to routines are readonly.
You also said there was output (ostensibly Official business!
, but perhaps sometimes something else, eg ()
?).
You didn't mention a say
or similar routine for displaying output. How could that be? Let's introduce a say
.
So, putting these things together, and applying pretzel logic, I arrived here:
sub named(:official($private)) { "Official business!" if $private }
my $private;
$private = False;
say named :official; # Official business!
say named :!official; # ()
say named official => False; # ()
say named :official(False); # ()
say named; # ()
An interpretation of this as solving the riddle:
()
is not "no output". So it doesn't contradict your Q narrative.
We've written $private = False
. It has no impact on the code, because of lexical scoping, but we did write it. :)
Am I warm?