Re: Thread
- To: mathgroup at smc.vnet.net
- Subject: [mg53252] Re: Thread
- From: Carlo Teubner <"see signature."@example.com>
- Date: Mon, 3 Jan 2005 04:29:29 -0500 (EST)
- References: <cr8eem$r86$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
I have found a solution that works. My original problem with premature
evaluation of f is easily solved by doing Thread[F[...]] /. F -> f
instead of Thread[f[...]].
There were some other problems however. In case anyone is interested,
this is what I've now come up with.
ThreadOptions[f_[args___, opts___?OptionQ], spec___] :=
Module[{fth=Thread[F[args], spec], oth},
If[Head[fth]===F, F[args,opts],
oth = Inner[#2->#1&, Thread[{opts}[[All,2]], {opts}[[All,1]], seq];
Which[ Head[oth]===seq, Append[#, oth]& /@ fth,
Length[oth]==Length[fth], Inner[Append, fth, oth, List],
True, ERROR
] /. seq -> Sequence
]
] /. F -> f
I realise one could possibly do this in a less cumbersome way by
transforming, e.g.,
f[a, {b,c}, Opt -> {1,2}]
to
f[a, {b,c}, {1,2}],
then applying Thread, and then putting the "Opt ->" rules back in.
However, in that case one couldn't honour the optional parameters in
Thread; and also then f[a, Opt->{1,2}] would become
{f[a, Opt->1], f[a, Opt->2]} which I don't really want (i.e. a function
will thread over only its options, even if it doesn't thread over its
other arguments).
Carlo
--
C Teubner t offline de
dot at minus dot
...oops: "on" not "off" :)