home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: sci.math.symbolic
- Path: sparky!uunet!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!fmmoore
- From: fmmoore@athena.mit.edu (Fes-Mike Moore)
- Subject: evaluating locals in returned procs
- Message-ID: <FMMOORE.92Nov13130659@copilot.mit.edu>
- Sender: news@athena.mit.edu (News system)
- Nntp-Posting-Host: copilot.mit.edu
- Organization: Massachusetts Institute of Technology
- Distribution: sci
- Date: Fri, 13 Nov 1992 18:07:16 GMT
- Lines: 39
-
- I'm writing for someone who would like to use maple to generate
- procedures that are function transforms. What he'd like to do is be
- able to call stretch:
-
- f := stretch(sqrt);
-
- and have f(3) return f(3/2). The original idea for coding it was:
-
- stretch := proc(func)
- proc (v) func(v/2) end
- end;
-
- but stretch returns:
-
- proc(v) func(v/2) end;
-
- i.e., func doesn't get evaluated until the returned procedure is
- executed. It's possible to do:
-
- stretch := proc(func)
- returned_function := func
- proc (v) returned_function(v/2) end
- end;
-
- where returned_function is a global (so that returned_function is
- defined when stretch(sqrt)(3) is evaluated, but I'd rather not use a
- global for this.
-
- If Lisp were the language being used here, something like:
-
- (defun stretch (func)
- (list 'lambda '(x) (list func '(* x 2))))
-
- so that func would get eval'ed in the call to stretch(), not
- stretch()(). Any ideas on how to do this? Or if it's possible?
- Thanks...
- --
- Fes-Mike Moore
- CSSC Student Consultant
-