As I understand, Dynamic Variables are looked up at runtime. I want to use them to enable parametrization similar to racket parameters.
To do so, I have to set a default that should be overridable, but not necessarily changable. My current approach is fairly simplistic:
my $*param ::= 42;
sub parameterized-function { say $*param };
parameterized-function();
do {
my $*param ::= 15;
parameterized-function();
}
Which works just fine - except that it introduces the name of the parameter on the outer scope. Beyond just feeling untidy, this has the side-effect that my $*param = 15;
causes mayhem if used on the file level.
What I would like to do instead is check if the parameter has been defined on the call stack, along the lines of:
sub parameterized-function { if defined($*param) { say 42 } else { say $*param } };
So, is it possible to perform such a check, if so how is it done?