Front page | perl.perl6.language |
Postings from November 2002
Dynamic scoping (take 2)
Thread Next
From:
Me
Date:
November 23, 2002 18:48
Subject:
Dynamic scoping (take 2)
Message ID:
0db401c29363$a3d229a0$6601a8c0@ralph
First, I'd like to confirm I've understood
C<temp> and C<let> right:
1. C<temp> dynamically scopes changes to a
variable's value to the enclosing block.
It does not dynamically scope the name.
The variable can obviously be a global.
It can also make sense if it is lexical.
Is the latter currently allowed?
2. C<let> is a conditional C<temp>; it only
restores a variable's value if, on exit
from the enclosing block, the block is
somehow considered to have "failed". It
can be applied to a global or lexical.
The above two features are basically sugar
for what would otherwise be achieved with
paired FIRST/LAST/UNDO blocks.
Both must be applied to an existing variable.
Next, I want to do a better job of stating
a problem I wonder about:
Consider "environmental" values such as
"screen sizes, graphics contexts, file
handles, environment variables, and
foreign interface environment handles." [1]
Consider a sub One that is going to call
a 10 deep stack of subs such that sub Ten
needs to access one of these environmental
values. How do you pass the data?
A. Globals. Bad. Disastrous in threads.
B. Passed as args to all intervening subs.
Verbose. Sometimes incredibly verbose.
C. Aggregate info into objects. But then
you still have to do either 1 or 2 above
with the object references. And it's a
shame to be forced to the object paradigm
unnecessarily.
D. Use $CALLERS::. Relatively succinct, but
definitely error-prone and ugly.
Given what I understand of Perl 6 syntax,
Parrot, and Perl philosophy, I suspect P6
should, and could fairly easily, provide a
good solution to the problem outlined above.
Does anyone agree the problem I've outlined
is inadequately addressed by $CALLERS::?
In previous emails I've suggested:
1. The notion of something like attaching
a C<passed> property on variables, and
picking appropriate defaults for its
args (not/ro/rw), to allow the writer
of a sub to easily strictly limit what
a called sub can access.
2. The notion of args that are explicitly
defined in a sub's sig but implicitly
passed. This kills most of the verbosity
of B above, while, in combination with
the previous point, being otherwise just
as safe as passing args explicitly all
the way down the call stack.
[1]
http://tinyurl.com/2yhl
--
ralph
Thread Next
-
Dynamic scoping (take 2)
by Me