Re: procedures and environments

Max Hailperin <max@gac.edu>
5 Nov 1999 01:33:05 -0500

          From comp.compilers

Related articles
procedures and environments debray@CS.Arizona.EDU (1999-11-04)
Re: procedures and environments rweaver@ix.netcom.com (1999-11-05)
Re: procedures and environments max@gac.edu (Max Hailperin) (1999-11-05)
Re: procedures and environments dlmoore@pgroup.com (David L Moore) (1999-11-05)
Re: procedures and environments gneuner@dyn.com (1999-11-05)
Re: procedures and environments plakal@nospam-cs.wisc.edu (1999-11-09)
Re: procedures and environments andi@complang.tuwien.ac.at (1999-11-09)
| List of all articles for this month |
From: Max Hailperin <max@gac.edu>
Newsgroups: comp.compilers
Date: 5 Nov 1999 01:33:05 -0500
Organization: Gustavus Adolphus College
References: 99-11-028
Keywords: code, optimize

debray@CS.Arizona.EDU (Saumya K. Debray) writes:


...In other words, a call would
> transfer control to the callee, which could either allocate an
> environment, or---if it chose to not allocate an environment for
> itself---execute in the caller's environment.
...
> [Seems to me it'd happen sort of automagically if a routine had no
> variables of its own but instead used only variables from the up-level
> routine. You'd skip allocating a frame pointer and use the caller's
> frame. I agree that calling sequences without separate frame pointers
> make this pretty yucky. -John]


It seems to me a slight clarification is needed here -- execution in
the caller's environment would only be an automagic consequence of
having no local variables if the procedure were dynamically scoped.
With lexcial scoping, it would be executing in its parent's
environment, which might not be the same as its caller's environment.
So in a dynamically scoped language (for example, ancient versions of
lisp) Debray's question would need no more answer. But the
interesting interpretation of Debray's question is whether anyone has
a language that is normally lexically scoped, but in which individual
procedures can be marked as dynamically scoped. I know of no such
language. The only linguistic devices I've seen for mixing lexical
and dynamic scoping in a single language involve marking individual
*variables* (or bindings) as to how they should be scoped, rather than
procedures. What we really want for Debray's problem, as I understand
it, is a situation where if the nesting of procedures were as follows


p1
  p2
  p3
    p4
    p5


and p3 and p5 both have local variables x, and p2 is marked as a
special dynamically-scoped procedure, then if p3 calls p2, p2 has
access to p3's x, but if p3 calls p5 which in turn calls p4, then p4
has access to p3's x rather than p5's.


  -Max Hailperin
    Associate Professor of Computer Science
    Gustavus Adolphus College
    800 W. College Ave.
    St. Peter, MN 56082
    USA
    http://www.gustavus.edu/~max/
[Well, it could also be an automagic consequence of having no local
variables and only referring to variables in the immediate caller's
scope, e.g., code like most C code. -John]







Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.