2010-02-28

nested subprograms

2.4: adda/nested subprograms:

. nested sub's have 2 special properties
(2 reasons why they should be nested):
the nestedSub' may be so specialized
as to be of use only to its ownerSub';
in this case,
nesting restricts the nestedSub's name
to the ownerSub's namespace,
so as to not clutter up the global namespace .
. another special property of nesting
is that a nestedSub has access to the locals of ownerSub,
which practically means that a call to nestedSub
needs a pointer to the caller's act'rec .
. this involves a form of generics:
it's being owned by a function class whose members are
sharing the same function definition
but are distinguished by having separate act'rec's .
. assuming a nestedSub does access some ownerSub`locals,
then each ownerSub instance needs to set up a record
containing pointers to the needed locals,
and then pass that record with each call to nestedSub(x) .
. say the record would be called [shared with nestedSub],
then each call would be:
nestedSub([shared with nestedSub], x),
[2.6:
. a nested generic is requiring 2 layers of instantiation:
being nested requires a partial instantiation
that defines who the current owner is,
and then the owner can set up
numerous instantiations of this owned generic:
nestedGenericSub([shared with nestedSub], [genericInstanceSub`args], x) .
]

No comments:

Post a Comment