Path: utzoo!mnetor!uunet!husc6!sri-unix!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.lang.misc Subject: Re: Var scoping in Wirth-type languages (was: Poor Algorithms) Message-ID: <758@cresswell.quintus.UUCP> Date: 11 Mar 88 09:25:30 GMT References: <3821@ihlpf.ATT.COM> <2791@enea.se> <3949@ihlpf.ATT.COM> <4760@sigi.Colorado.EDU> Organization: Quintus Computer Systems, Mountain View, CA Lines: 27 In article <3949@ihlpf.ATT.COM>, nevin1@ihlpf (00704a-Liber) writes: > If some vars are declared 'globally' (at the topmost level), it is very > inefficient to access those variables in a procedure declared more than 1 > or 2 levels deep. There is a way to implement scoping that alleviates this > inefficiency, however. Can you say "display"? I knew you could. You don't even need a full display. Just retain a pointer to each level of the display you actually need. E.g. program main(..); var x; procedure one(...); var y; procedure two(...); var z; procedure three(...); begin {use x and y but not z} end; --> procedure three(...); var one_ptr: ^frame of one; begin one_ptr := self^.parent^.parent; {use global^.x and one_ptr^.y} end; Any Pascal compiler which searches the static chain on every non-local variable reference is a toy.