home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / sci / math / symbolic / 2964 < prev    next >
Encoding:
Text File  |  1992-11-14  |  1.4 KB  |  52 lines

  1. Newsgroups: sci.math.symbolic
  2. Path: sparky!uunet!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!fmmoore
  3. From: fmmoore@athena.mit.edu (Fes-Mike Moore)
  4. Subject: evaluating locals in returned procs
  5. Message-ID: <FMMOORE.92Nov13130659@copilot.mit.edu>
  6. Sender: news@athena.mit.edu (News system)
  7. Nntp-Posting-Host: copilot.mit.edu
  8. Organization: Massachusetts Institute of Technology
  9. Distribution: sci
  10. Date: Fri, 13 Nov 1992 18:07:16 GMT
  11. Lines: 39
  12.  
  13. I'm writing for someone who would like to use maple to generate
  14. procedures that are function transforms.  What he'd like to do is be
  15. able to call stretch:
  16.  
  17.     f := stretch(sqrt);
  18.  
  19. and have f(3) return f(3/2).  The original idea for coding it was:
  20.  
  21.     stretch := proc(func)
  22.         proc (v) func(v/2) end
  23.     end;
  24.  
  25. but stretch returns:
  26.  
  27.     proc(v) func(v/2) end;
  28.  
  29. i.e., func doesn't get evaluated until the returned procedure is
  30. executed.  It's possible to do:
  31.  
  32.     stretch := proc(func)
  33.         returned_function := func
  34.         proc (v) returned_function(v/2) end
  35.     end;
  36.  
  37. where returned_function is a global (so that returned_function is
  38. defined when stretch(sqrt)(3) is evaluated, but I'd rather not use a
  39. global for this.
  40.  
  41. If Lisp were the language being used here, something like:
  42.  
  43.     (defun stretch (func)
  44.         (list 'lambda '(x) (list func '(* x 2))))
  45.  
  46. so that func would get eval'ed in the call to stretch(), not
  47. stretch()().  Any ideas on how to do this?  Or if it's possible?
  48. Thanks...
  49. --
  50. Fes-Mike Moore
  51. CSSC Student Consultant
  52.