Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!elroy.jpl.nasa.gov!ames!haven!wam!nebel From: nebel@wam.umd.edu (Chris D. Nebel) Newsgroups: comp.sys.mac.programmer Subject: Re: Variable procedures in Pascal Message-ID: <1990Nov30.160219.6428@wam.umd.edu> Date: 30 Nov 90 16:02:19 GMT References: <1990Nov23.082345.12074@portia.Stanford.EDU> <2434@krafla.rhi.hi.is> <46833@apple.Apple.COM> Sender: usenet@wam.umd.edu (USENET Posting) Reply-To: nebel@wam.umd.edu (Chris D. Nebel) Organization: University of Maryland at College Park Lines: 45 In article <46833@apple.Apple.COM> lins@Apple.COM (Chuck Lins) writes: >In article <2434@krafla.rhi.hi.is> aries@rhi.hi.is (Reynir Hugason) writes: >>As far as I can remember MPW (and Think) only have procedural parameters, >>i.e. you can only pass a procedure (or a function) to another procedure. >>No tricky procedural variables. Actually, it can be done by exploiting MPW Pascal's INLINE construct. What you do is something like this: procedure OneWay(stuff: StuffType); ... procedure AnotherWay(stuff: StuffType); ... procedure DoStuff(stuff: StuffType; useProc: ProcPtr); INLINE {whatever the opcodes are for move.l (sp)+, A0; jmp (A0) } var theProc: ProcPtr; begin theProc := @OneWay; DoStuff(stuff, theProc); { does it OneWay } theProc := @AnotherWay; DoStuff(stuff, theProc); { does it AnotherWay } end. A couple of caveats here: one, OneWay, AnotherWay, &c must have the same parameters. (If you're into playing really funny games with your compiler's brain, the only real requirement is that the parameters for each procedure occupy the same amount of space on the stack.) Also, they must be globally scoped, same as procedures used for filterProcs. How it works: what the DoStuff stub is doing is to take the last parameter it was passed (the ProcPtr) and then jump to that address. Note that this won't necessarily work on any compiler other than MPW Pascal. Different compilers handle parameters in different ways. If this doesn't make any sense to you, write me and I'll try to explain further. Chris Nebel nebel@wam.umd.edu