RE: Functional Expression Meaning (was:A Functional Expression Trick)
- To: mathgroup at smc.vnet.net
- Subject: [mg23931] RE: Functional Expression Meaning (was:[mg23859] A Functional Expression Trick)
- From: "David Park" <djmp at earthlink.net>
- Date: Fri, 16 Jun 2000 00:57:12 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
> -----Original Message----- > From: Allan Hayes [mailto:hay at haystack.demon.co.uk] To: mathgroup at smc.vnet.net > Dear David and Hartmut, > I have come across some problems with Hartmut's solution, toFunc, > as written > up by David. > I offer new version, toFunc2 > Dear Allan and Hartmut, Allan's solution is more robust than Hartmut's, but it leaves out the case of pure functions in short form, using slot numbers directly. So I added an extra rule for that case. Here is it: toFunc::usage = "toFunc[expr] will convert an expression of pure functions into a pure \ function."; toFunc[expr_] := ReleaseHold[Function @@ ({expr} /. (F_ /; F === Function)[vars_, body_] :> Apply[F[vars, Hold[body]], Slot /@ Range[Last[Dimensions[Unevaluated[{vars}]]]] ] /. (F_ /; F === Function)[ body_] :> Hold[body] )] I think this is a very useful routine. Thanks to both of you. David Park djmp at earthlink.net http://home.earthlink.net/~djmp/