Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!spool.mu.edu!munnari.oz.au!brolga!uqcspe!cs.uq.oz.au!grue From: grue@cs.uq.oz.au (Frobozz) Newsgroups: comp.sys.handhelds Subject: Re: HP-48 programming problem Message-ID: <668@uqcspe.cs.uq.oz.au> Date: 9 Apr 91 09:08:32 GMT References: <1991Apr9.021224.27070@usenet.ins.cwru.edu> Sender: news@cs.uq.oz.au Reply-To: grue@cs.uq.oz.au Lines: 50 In article <1991Apr9.021224.27070@usenet.ins.cwru.edu> rkb@po.CWRU.Edu (Robert K. Brunner) writes: >I had a problem debugging a program today, and I was wondering if anyone >had encountered the same problem before. The problem isn't a bug, but >it is annoying behavior. >Suppose you have the following variables: >P1: \<< \-> a \<< 'a' INC \>> \>> >INC: \<< \-> a \<< a INCR DROP \>> \>> There is a way to do what you desire. My reversi program for the hp28 made extensive use of it. You have to trick the parser into thinking that the variable 'a' is a local variable without including '-> a' in the executable code. Write a Make_INC routine that looks like (I've labeled the double brakcets): Make_INC: \<< \-> a \<< \<< a INCR DROP \>> 'INC' STO \>> \>> A B C C B A Then run this program and you have a version of INC that binds 'a' to a local variable but it doesn't define 'a' itself. The reason that this works is that when the Make_INC routine is parsed 'a' is a local variable, because it is defined at block level A and it is permitted to be used at level B. The parser then processes level C and says that 'a' is local. When this is run, the block C is pushed onto the stack and then stored into the variable INC, without re-evalulating the bindings. This means that 'a' (inside block C) still binds to a local variable. When your program P1 calls INC, the locally bound 'a' refers the the 'a' defined inside of P1 !!! You can now have global, local variables. If you try to run the new INC routine and there is no 'a' defined by any context along the call chain then you get an error message (undefined local?). Try this, it doesn't do any harm. Cute feature isn't it. Pauli seeya Paul Dale | Internet/CSnet: grue@cs.uq.oz.au Dept of Computer Science| Bitnet: grue%cs.uq.oz.au@uunet.uu.net Uni of Qld | JANET: grue%cs.uq.oz.au@uk.ac.ukc Australia, 4072 | EAN: grue@cs.uq.oz | UUCP: uunet!munnari!cs.uq.oz!grue f4e6g4Qh4++ | JUNET: grue@cs.uq.oz.au --