Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!nstn.ns.ca!news.cs.indiana.edu!att!linac!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!emory!gatech!prism!gus From: gus@prism.gatech.EDU (gus Baird) Newsgroups: comp.lang.pascal Subject: Re: procedures as parameters to procedures Message-ID: <20978@hydra.gatech.EDU> Date: 1 Feb 91 12:00:46 GMT References: <25782@adm.brl.mil> Organization: School of ICS, Georgia Institute of Technology Lines: 59 In article <25782@adm.brl.mil> VMAN%PACEVM.BITNET@uga.cc.uga.edu ( cliff) writes: >hi, > we run vs pascal 2.1 on vm/sp 6. is it possible to pass as a procedure > parameter a procedure name with a parameter list? for example, > >program main (input,output); > >var word: packed array(1..5) of char; > >procedure abc(procedure xyx(var string: packed array(1..5) of char);i:integer); > . > . >procedure blah(var string: packed array(1..5) of char); > . > . > begin (* main program *) > . > . > abc(blah(word),3) > end. > >i can pass procedure names without parameter lists as parameters to a >procedure, but i get errors using the above code. i don't know if this >is a restriction on our particular product or not. the pascal report >(wirth & jensen) seems to indicate you can do this. does anyone have an >example of code where this has been successfully done? any help is >appreciated. when you say > abc(blah(word),3) you're not passing the procedure blah, you're trying to invoke it - like, if it were a function procedure, you'd be passing the RESULT of the function. when you pass a procedure you pass just the name, it's the job of the guy you pass it TO to invoke it with whatever parameters HE decides to use. why would you want to pass the procedure WITH the parameters? if you know the parameter list, YOU can invoke the procedure and pass the answer instead of the question... anyway, you can't, not this way. to do that you'd have to give abc another parameter, the argument to give to xyz. your main problem with a balky compiler may be >procedure blah(var string: packed array(1..5) of char); where you're trying to declare a procedure parameter of anonymous type. Pascal requires parameters' types to be named, doesn't it? you probably should have said: type PAC5 = packed array [1..5] of char; ... procedure abc(procedure xyz(var P: PAC5); i: integer); ... procedure blah(var P: PAC5); ... abc(blah,3) -- gus Baird, College of Computing Georgia Institute of Technology, Atlanta Georgia, 30332 uucp: ...!{allegra,amd,hplabs,seismo,ut-ngp}!gatech!prism!gus ARPA: gus@cc.gatech.edu