home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / pascal / 4475 next >
Encoding:
Text File  |  1992-07-20  |  1.9 KB  |  54 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!cleveland.Freenet.Edu!bx304
  3. From: bx304@cleveland.Freenet.Edu (Jeff Epler)
  4. Subject: Re: Functions and Procedures as Parameters
  5. Message-ID: <1992Jul21.050043.7238@usenet.ins.cwru.edu>
  6. Sender: news@usenet.ins.cwru.edu
  7. Nntp-Posting-Host: cwns16.ins.cwru.edu
  8. Reply-To: bx304@cleveland.Freenet.Edu (Jeff Epler)
  9. Organization: Case Western Reserve University, Cleveland, OH (USA)
  10. References: <BrpxpG.351@ux1.cso.uiuc.edu>  
  11. Date: Tue, 21 Jul 92 05:00:43 GMT
  12. Lines:       41
  13.  
  14.  
  15. In a previous article, husak@ux1.cso.uiuc.edu (Stephen R. Husak) says:
  16.  
  17. >I've been trying to implement the following in TP5.5... Could someone
  18. >either clue me in or tell me if it is possible.
  19. >
  20. >I want to pass a function into another function:
  21. >
  22. >eg --    function First(a,b: real;
  23. >               function test(x:integer):integer);
  24. >    
  25. >    { rest of function follows }
  26. >
  27. >I know this is implemented in some versions of Pascal. Is this possible
  28. >in TP and if it is what am I doning wrong...???? Thanks!
  29. >
  30.  
  31. I believe so.  But, this is from memory and my copy of TP isn't handy.
  32.  
  33. I *think* that one must declare a TYPE that is a function.  What you
  34. have above doesn't work for the same reason that function
  35. george(harry:array[1..20] of char):char; doesn't work.
  36.  
  37. Try something like this:
  38.  
  39. type 
  40.  xfunction:function(x:integer):integer;
  41.  
  42. function yfunction(first,last:integer; theFunc:xFunction):integer
  43.  
  44. Then in the procedure it should look something like:
  45.  inc(temp,theFunc(i));
  46.  
  47. Just as though theFunc was a 'normal' function.  (It is, however, a
  48. pointer.  And whenever someone talks of pointers, I get hives.  It
  49. reminds me of when I tried to learn C. :)
  50. -- 
  51. |Jeff Epler               Additions Welcome                ;-) >{8-) |
  52. | :) (=( =-] (-= Celebrating the variety of faces =-> :^) {-= |-) (: |
  53. |                                                   Lincoln, Nebraska|
  54.